Solved

calling a script from c

Posted on 2000-03-07
9
370 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
 
LVL 84

Expert Comment

by:ozo
ID: 2594841
also be sure that the `rename` is executable
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now