Multiple scripts in one file

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2005
Posts: 78
Reputation: nanodano is an unknown quantity at this point 
Solved Threads: 2
nanodano's Avatar
nanodano nanodano is offline Offline
Junior Poster in Training

Multiple scripts in one file

 
0
  #1
Apr 5th, 2007
Is it possible to have a perl script and a bash script in one file? Like:

  1. #!/bin/perl
  2. print "This is perl";
  3. #exit perl
  4.  
  5. #!/bin/bash
  6. echo "This is bash"
  7. exit 0

This is probably just a complicated solution to a simple problem. I have a perl script, and at the end of it, I want to make a couple calls that I normal write in the shell.

I tried this but it does not work:

  1. $command = "ps";
  2. system $command;

Any help is appreciated greatly.
- Dano
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 78
Reputation: nanodano is an unknown quantity at this point 
Solved Threads: 2
nanodano's Avatar
nanodano nanodano is offline Offline
Junior Poster in Training

Re: Multiple scripts in one file

 
0
  #2
Apr 5th, 2007
I found a solution to my own problem now. =P

This works:

  1. #!/bin/perl
  2. use Shell;
  3. $command = echo("parameters", "go", "here");
  4. print $command; #performs echo
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Multiple scripts in one file

 
0
  #3
Apr 5th, 2007
I'm not sure if this is a wise way to do this, but it should work:


  1. $ENV{PATH}='/bin/perl:/bin/bash';
  2. open (PS, 'ps |') or die "$!";
  3. print <PS>;
  4. close PS;
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Multiple scripts in one file

 
0
  #4
Apr 5th, 2007
this does not work because the system() function does not return the output of the process:

  1. $command = "ps";
  2. system $command;

You use backtiks `` or qx// to capture process output:

  1. $output = qx/ps/;
  2. print $output;


But on further review of interprocess communications, perldocs recommends using this safe construct:

  1. open PS, "-|", "ps" or die $!;
  2. print <PS>;
  3. close PS;

or stick with the Shell module
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC