Basic system calls help.
Hi Everyone, its been a little while since i posted, been lurking though!
I'm writing a short program to try and sift through a mountain of data from some simulation results.
Basically, the user inputs some values corresponding to some variables in the schematic and it should change to the appropriate directory where the data is and plot a file.
The problem i'm having is that i get to where the user inputs data and i change to the directory but it doesn't stay in the directory. Is it possible to get it to do this?
Some brief code may help explain:
and so on.. if i do:
if(width < 10)
if(width < 20)
I get the right directory but if i do:
system("cd 2amp/eps/10mto20m/; pwd")
It prints the directory the program is in so i know its going in to the directory but coming straight back out. Is there a way to keep it into the directory once its in?
Or should i save the directory address as a variable to do later?
Thanks in advance for your time,
When you invoke the system() function, a new shell is created. Any changes to that shell (like the current directory), apply to that shell only. When the system function returns, that shell has gone away.
You're probably better off saving the path information in a variable.
Thanks, i tried saving the path info in variables but i can't seem to get it to work. I'm using tcsh and the c program seems to be implementing all my system calls in bourne shell. How do i change it so that it will use tcsh?
it doesn't seem to keeo the shell variables. Even if i stick to bourne shell. ie:
The variable is forgotten directly after the above command!
system("W_DIR=2amp/eps/3m6to10m; export W_DIR");
Have you tried the chdir() function?
Thanks a lot for your help but i've abandoned it! Really in the spirit of learning! ;)
Did it with a bash script instead.