?
Solved

Store System() call result in a string

Posted on 2008-10-31
5
Medium Priority
?
861 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 1500 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 35

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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 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