System cmds

P

Profetas

How can I use shell cmds with vars?
I would like to execute
system("cd var_path");
where the var_path is a variable that has the path.
is there any other way that enables me to use vars?


thanks
 
T

those who know me have no need of my name

in comp.lang.c i read:
How can I use shell cmds with vars?
I would like to execute
system("cd var_path");
where the var_path is a variable that has the path.
is there any other way that enables me to use vars?

build the string you want first. sprintf may be useful to you for that.
 
T

tweak

Profetas said:
How can I use shell cmds with vars?
I would like to execute
system("cd var_path");
where the var_path is a variable that has the path.
is there any other way that enables me to use vars?


thanks
You question is OS specific, and as I have been told,
is off topic for this list, which appears to dig deep
into ISO C99:

http://www.open-std.org/jtc1/sc22/wg14/

which is OS independent.

Nevertheless, if you are talking about a executing a file,
here's the best example I could find for Unix:

http://www.gnu.org/software/libc/ma...reation-Example.html#Process Creation Example

Read up from the example. It explains all the types and functions.

If you want to learn more about your computer, mudge wrote a great
article on creating a buffer overflow that shows the use of an exec()
function and then converts it to assembly and finally to op codes. It
a great read if you want to learn more about how instructions are executed.

Here's a link to that article:

http://www.insecure.org/stf/mudge_buffer_overflow_tutorial.html

I do not code windows, so I don't have a clue as to how to help you there.

Cheers,

Brian
 
K

Kieran Simkin

those who know me have no need of my name said:
in comp.lang.c i read:


build the string you want first. sprintf may be useful to you for that.

system() probably won't do what you want it to do either. The system()
function forks a child process, which I believe then runs your shell, which
then runs your command such as "cd". This will result in no change of
working directory for the parent process (which is probably what you're
trying to achieve). Try looking for the chdir() function in the standard C
library, this probably does do what you want.
 
K

Keith Thompson

Kieran Simkin said:
system() probably won't do what you want it to do either. The system()
function forks a child process, which I believe then runs your shell, which
then runs your command such as "cd". This will result in no change of
working directory for the parent process (which is probably what you're
trying to achieve). Try looking for the chdir() function in the standard C
library, this probably does do what you want.

The terms "fork", "child process", "shell", and "working directory"
are all system-specific. There is no chdir() function in the standard
C library, though there may be such a function in some system-specific
(POSIX?) library.

<OT>I think your answer would be correct in comp.unix.programmer.</OT>
 
M

Malcolm

tweak said:
You question is OS specific, and as I have been told,
is off topic for this list, which appears to dig deep
into ISO C99:
Actaully this one is on-topic. The details of the the "cd" command are
off-topic, of course, it may be a compact disk burner or a dc current
inverter for all we care, but how to pass a command line to "system" is
topical enough.
 
K

Keith Thompson

Malcolm said:
Actaully this one is on-topic. The details of the the "cd" command are
off-topic, of course, it may be a compact disk burner or a dc current
inverter for all we care, but how to pass a command line to "system" is
topical enough.

Agreed, but the question of whether system("cd var_path") will do what
you expect it to is system-specific and off-topic. (On Unix-like
systems, it will have no effect on the current process; on other
systems, I have no ides.)
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top