Solved

Store System() call result in a string

Posted on 2008-10-31
5
857 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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