Path: utzoo!attcan!uunet!seismo!dimacs.rutgers.edu!rutgers!cs.utexas.edu!yale!mintaka!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Calling system processes Message-ID: <18632@haddock.ima.isc.com> Date: 25 Oct 90 03:16:29 GMT References: <15657@mentor.cc.purdue.edu> Reply-To: karl@ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 19 In article <15657@mentor.cc.purdue.edu> shepherd@mentor.cc.purdue.edu (Mike Shepherd) writes: > I was wondering if there is a way to call system processes from a >C program, and how it would be done (this like 'ls','cd','more')? Depends on your operating system; check your manual to see which ones exist. Likely possibilities are functions named (or starting with) "system", "popen", "spawn", "exec". If the command you want to execute is fixed (rather than something entered by the user), there may already be a C interface to it, and you should probably use that instead of a subprocess. It's usually simpler to do opendir(), readdir(), closedir() than to try to parse the output of "ls". >I am most interest in the ability to change directories though. Use chdir(). Assuming a Unix system, you *must* use the C interface in this case, since the current directory is local to a process. If you were to do system("cd foo"), the subshell would change directories and then exit, which doesn't do you any good. Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint