Solved

calling a script from c

Posted on 2000-03-07
9
372 Views
Last Modified: 2010-04-02
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
Comment
Question by:zandyl
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 3

Accepted Solution

by:
msmits earned 80 total points
ID: 2592461
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
 
LVL 1

Expert Comment

by:ntdragon
ID: 2592779
try you use
execl(...);
or all the same functions
0
 
LVL 3

Expert Comment

by:arnond
ID: 2594818
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 84

Expert Comment

by:ozo
ID: 2594841
also be sure that the `rename` is executable
0
 
LVL 3

Expert Comment

by:arnond
ID: 2594886
ozo, isn't that what I suggested ???

Arnon David.
0
 
LVL 5

Expert Comment

by:PC_User321
ID: 2594958
Try using full path names for rm and rename, in case the script does not inherit the correct environment.
0
 
LVL 5

Expert Comment

by:PC_User321
ID: 2594962
.. and to bypass any aliases that might apply to them.
0
 

Author Comment

by:zandyl
ID: 2596160
thanks msmits.  i tried it and it works!!

zandyl
0
 
LVL 3

Expert Comment

by:msmits
ID: 2598598
Which one of my solutions?

Thanx for the grade!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question