×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how can i get perl to start a unix shell script?

how can i get perl to start a unix shell script?

how can i get perl to start a unix shell script?

(OP)
hi all,

I got my cgi baby rolling (kinda :) ) and i was wondering how i can get my cgi script to run my perl to begin a korn shell job??

Anyone know if it's possible??

i would probably use it across the network, ie, from this unix box along to the one in another part of the country across tcp/ip and then supply it my password and username and then launch the script, along with passing it a few variables sent from the script.

-- WAW!!

i know, i'v been to the doctors, they wondered why i havn't been in recently, and i told them i'v been ill..

Signing off,

Karl.

Karl Butterworth
karl_butterworth@ordina.co.uk

I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!

RE: how can i get perl to start a unix shell script?

There's a couple of ways to do this.  The first is to use "backtics", and the other is to use the "system" function call.

# Using backtics. Save the output from the shell
# script in $Result_String.
$Result_String = `/some/script/to/run`;

# Using system().  Again, save the output from the script.
$Result_String = system("/some/script/to/run");

I tend to use system(), as I have more trust in it to evaluate scalars that contain paths to scripts, argements, etc.




--
0 1 - Just my two bits

RE: how can i get perl to start a unix shell script?

(OP)
if you wasnt so far away, i would kiss you.. (i hoping now that you are far away, and you are probably hoping the same too :))
BUT, what if i was to just let the script run, ie if i was to read data rfom the html, and then wanted the html input to be a username, and then the CFGI reads it, passed it through into my linux box, and wanted to run a program to see if that username was available, and then i wanted to save the ip address coming in, and loads of other things?
- would i still be able to run the program as if it was commanded from the terminal??

Karl Butterworth
karl_butterworth@ordina.co.uk

I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!

RE: how can i get perl to start a unix shell script?

It depends...

Obviously, if the script needs some user intervention at some stage, then the answer is no.  You're running the page from a browser, and there's no input stream...

If the script doesn't generate any output, but it does return an exit status, then I'd strongly suggest you have a read of perldoc -f system.  There's a note in there about the return codes from external scripts/programs as they are reported by perl.

If you have some control over the script, I would suggest you send some simple responses depending upon results you want to return.  For example, if the user you are looking for exists, do an echo "yes" in the shell script.  Otherwise, echo "no".

Of course, the ultimate answer would be to replace the shell script with a function in your perl program.  This might be easy, or it might be difficult.  It all depends what you want to do :)  You hinted that you want to see if a user exists - take a look at perldoc -f getpwent for details on perl's "get user details" functions.

So, to summarise, it all depends how complex you want to get.  I suggest taking a look at the shell scripts and re-writing them as perl functions.  You will get some performance benefits (no sub-process being forked), and you will learn some more perl along the way.  That's always a good thing! ;^)

PS, a thanks would have been fine, but I appreciate the sentiment ;^)




--
0 1 - Just my two bits

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close