| | |
Multiple scripts in one file
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Is it possible to have a perl script and a bash script in one file? Like:
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:
Any help is appreciated greatly.
- Dano
Perl Syntax (Toggle Plain Text)
#!/bin/perl print "This is perl"; #exit perl #!/bin/bash echo "This is bash" 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:
Perl Syntax (Toggle Plain Text)
$command = "ps"; system $command;
Any help is appreciated greatly.
- Dano
I found a solution to my own problem now. =P
This works:
This works:
Perl Syntax (Toggle Plain Text)
#!/bin/perl use Shell; $command = echo("parameters", "go", "here"); print $command; #performs echo
I'm not sure if this is a wise way to do this, but it should work:
Perl Syntax (Toggle Plain Text)
$ENV{PATH}='/bin/perl:/bin/bash'; open (PS, 'ps |') or die "$!"; print <PS>; close PS;
this does not work because the system() function does not return the output of the process:
You use backtiks `` or qx// to capture process output:
But on further review of interprocess communications, perldocs recommends using this safe construct:
or stick with the Shell module
Perl Syntax (Toggle Plain Text)
$command = "ps"; system $command;
You use backtiks `` or qx// to capture process output:
Perl Syntax (Toggle Plain Text)
$output = qx/ps/; print $output;
But on further review of interprocess communications, perldocs recommends using this safe construct:
Perl Syntax (Toggle Plain Text)
open PS, "-|", "ps" or die $!; print <PS>; close PS;
or stick with the Shell module
![]() |
Similar Threads
- How to stop opening multiple instance for a jar file (Java)
- Multiple Exe Project handle Code with VB6.0 (Visual Basic 4 / 5 / 6)
- how to call a function from one file to another file (Shell Scripting)
- 0 file in root? (Darwin, X11 and BSD)
- Passing result codes to a batch file (Python)
- compile header file (C++)
Other Threads in the Perl Forum
- Previous Thread: String replacement in a file
- Next Thread: Tomcat-Perl-Perl
Views: 2665 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Perl





