• C

calling a script from c

hello,
i wrote a script named 'renamefile' that will execute 3 or 4 separate commands: (eg below)
  rm filename1
  rename filename2 filename1
  rename filename3 filename2

i would like to call this script inside my c program.  i'm using SCO Unix V as the platform.  i tried using the command
'system("./renamefile");' and it didn't work.  could anybody else give me suggestions.  thanks a bunch.

zandyl
zandylAsked:
Who is Participating?
 
msmitsConnect With a Mentor Commented:
You should either use the she-bang notation in your script or explicitly call a shell to execute your script.

The she-bang solution (rewrite script) and make sure the execute bits are on:

#!/bin/sh
rm filename1
rename filename2 filename1
rename filename3 filename2

Or the shell solution:

system("/bin/sh ./renamefile");

0
 
ntdragonCommented:
try you use
execl(...);
or all the same functions
0
 
arnondCommented:
did you make sure that the 'renamefile' is executable ?
try to do 'chmod a+x renamefile'. this will make the file executable.

Arnon David.
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
ozoCommented:
also be sure that the `rename` is executable
0
 
arnondCommented:
ozo, isn't that what I suggested ???

Arnon David.
0
 
PC_User321Commented:
Try using full path names for rm and rename, in case the script does not inherit the correct environment.
0
 
PC_User321Commented:
.. and to bypass any aliases that might apply to them.
0
 
zandylAuthor Commented:
thanks msmits.  i tried it and it works!!

zandyl
0
 
msmitsCommented:
Which one of my solutions?

Thanx for the grade!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.