Solved

calling a script from c

Posted on 2000-03-07
9
373 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
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

Suggested Solutions

Title # Comments Views Activity
how to declare a 2-dimensional version of strlen 4 217
How to organize data in excel ? 2 115
Why does module make constant click noise ? 9 135
Problem to show menu 5 93
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

790 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