system question

D

David Schwartz

I'm writing a little c program and one of things I'm trying to get it to do
is cd to a particular directory and then run an exe that is on my path, as
follows...

strcpy(working_string, "c:\\davedata\\bats\\ks.exe fnord");
system("cd \\playtime\\d\\build\\html");
system(working_string);

But ks.exe does not seem to be invoked on the files in the
\\playtime\\d\\build\\html directory.

Can someone tell me how to do this?
 
J

Jens.Toerring

David Schwartz said:
I'm writing a little c program and one of things I'm trying to get it to do
is cd to a particular directory and then run an exe that is on my path, as
follows...
strcpy(working_string, "c:\\davedata\\bats\\ks.exe fnord");
system("cd \\playtime\\d\\build\\html");
system(working_string);
But ks.exe does not seem to be invoked on the files in the
\\playtime\\d\\build\\html directory.
Can someone tell me how to do this?

The first invocation of system() creates a shell in which you do the 'cd'.
Then the shell exits. As the next step you invoke a completely new shell
by calling system() again that has no idea about the working directory of
the other shell that's already dead. Execute both commands in the _same_
call of system().
Regards, Jens
 
D

Dan Pop

In said:
The first invocation of system() creates a shell in which you do the 'cd'.
Then the shell exits. As the next step you invoke a completely new shell
by calling system() again that has no idea about the working directory of
the other shell that's already dead. Execute both commands in the _same_
call of system().

And if your shell doesn't allow this directly, build a script
containing the two commands and execute that script with system().

Dan
 
C

CBFalconer

David said:
I'm writing a little c program and one of things I'm trying to
get it to do is cd to a particular directory and then run an exe
that is on my path, as follows...

strcpy(working_string, "c:\\davedata\\bats\\ks.exe fnord");
system("cd \\playtime\\d\\build\\html");
system(working_string);

But ks.exe does not seem to be invoked on the files in the
\\playtime\\d\\build\\html directory.

Can someone tell me how to do this?

Not here. The C language has neither directories nor exes nor
paths. You want a group dealing with your peculiar system, which
I suspect to be either Windows or MsDos.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,362
Latest member
ChandaWagn

Latest Threads

Top