Solved

Store System() call result in a string

Posted on 2008-10-31
5
859 Views
Last Modified: 2012-08-14
How do I store the result of a system call?

For example: char *path = system("pwd");

I know the above is not possible. Can you tell me what i need to do to store the result of the pwd command?
0
Comment
Question by:Cool-Guy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 22848995
>> Can you tell me what i need to do to store the result of the pwd command?

Don't use system. Consider using popen instead :

        http://opengroup.org/onlinepubs/007908775/xsh/popen.html

You can then read the output of the command the same way you read a file.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22849001
Obviously, if you only need to retrieve the working directory, you can use platform specific methods, like getcwd :

        http://linux.die.net/man/3/getcwd
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 22872187
A system() call can't change the working directory of the calling process
0
 

Author Closing Comment

by:Cool-Guy
ID: 31511997
thanks
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22896141
May I ask why you gave a B grade ? that usually means that something was missing in the answer and/or that something is still unclear. If that's the case, then do not hesitate to ask for clarification where needed.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question