[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

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
0
zandyl
Asked:
zandyl
  • 2
  • 2
  • 2
  • +3
1 Solution
 
msmitsCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now