CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
system command for running command line functions

 



pulkitjain25
New User

Oct 27, 2010, 4:08 PM

Post #1 of 3 (245 views)
system command for running command line functions Can't Post

Hi,
How to give shell commands from within perl?
I tried the following in my perl code but to no avail

system 'cd ..';
system 'echo $foo';

Regards
Pulkit


BillKSmith
Veteran

Oct 28, 2010, 5:55 AM

Post #2 of 3 (237 views)
Re: [pulkitjain25] system command for running command line functions [In reply to] Can't Post

What exactly did you expect to happen, or prhaps more important what did you want to do? You probably should be using perl commands rather than system commands.
Good Luck,
Bill


rovf
Veteran

Oct 28, 2010, 8:35 AM

Post #3 of 3 (236 views)
Re: [pulkitjain25] system command for running command line functions [In reply to] Can't Post

Your first system command opens a shell, does a cd to the parent directory and closes (which means that your working directory is still the same as before, because the cd was run in a child process).

The second system command outputs the variable foo. Assuming that foo is an environment variable, you can easier do it from within Perl using

say($ENV{foo})

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives