Hello,
I am trying to get a Perl script that I have to make a call to a Bourne
Shell script...'kick it off' so to speak...what is the command I would use
to do that?
Thanks for any pointers!
A.
I am trying to get a Perl script that I have to make a call to a Bourne
Shell script...'kick it off' so to speak...what is the command I would use
to do that?
Thanks for any pointers!
A.
#!/usr/bin/perl
system("/path/to/bash/script");
Sorry if it's not what you have in mind ...
> I am trying to get a Perl script that I have to make a call to a Bourne
> Shell script...'kick it off' so to speak...what is the command I would use
> to do that?
> Thanks for any pointers!
> A.
> #!/usr/bin/perl
> system("/path/to/bash/script");
`/path/to/bash/script`;
I presonally prefer
$results=`/path/to/bash/script 2>&1`;
--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
> > Maybe too simple:
> > #!/usr/bin/perl
> > system("/path/to/bash/script");
> Nah. Too complex. :-)
> `/path/to/bash/script`;
> I presonally prefer
> $results=`/path/to/bash/script 2>&1`;
> --
> Sending unsolicited commercial e-mail to this account incurs a fee of
> $500 per message, and acknowledges the legality of this contract.
TIA,
A.
...
Can't you just do things sequentially instead of waiting an arbitraryQuote:> Thanks for the reply - that worked great, however, now it's executing so
> fast that it's running my bourne shell script before it is completely
> written. How would I go about inserting a pause for 30 seconds in the perl
> script?
--
--Ed L Cashin | PGP public key:
> ...
> > Thanks for the reply - that worked great, however, now it's executing so
> > fast that it's running my bourne shell script before it is completely
> > written. How would I go about inserting a pause for 30 seconds in the
perl
> > script?
> Can't you just do things sequentially instead of waiting an arbitrary
> amount of time?
> --
> --Ed L Cashin | PGP public key:
A.
> > ...
> > > Thanks for the reply - that worked great, however, now it's executing so
> > > fast that it's running my bourne shell script before it is completely
> > > written. How would I go about inserting a pause for 30 seconds in the
> perl
> > > script?
> > Can't you just do things sequentially instead of waiting an arbitrary
> > amount of time?
> > --
> > --Ed L Cashin | PGP public key:
> It takes longer for the Bourne Shell to be written to the file then it does
> for the Perl script to step through the code and run the Bourne Shell,
> causing the file to be malformed and execute with errors...Any ideas?
#! /usr/bin/perl -w
use strict;
&go;
sub go {
my $shfile = "/tmp/test-bourne.sh";
open SHFILE, "> $shfile" or die "Error: could not open $shfile";
print SHFILE "#! /bin/sh\n"
. "echo 'hi there!!!'\n";
close SHFILE;
chmod 0755, $shfile;
system $shfile;
}
... and it works just like you'd expect:
hi there!!!
--
--Ed L Cashin | PGP public key:
Bruce> `/path/to/bash/script`;
That's working hard when it doesn't need. Don't use backquotes
in a void context.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
>> Maybe too simple:
>> #!/usr/bin/perl
>> system("/path/to/bash/script");
>Nah. Too complex. :-)
> `/path/to/bash/script`;
Also, if the command being executed takes arguments, I definitely preferQuote:>I presonally prefer
> $results=`/path/to/bash/script 2>&1`;
system("/path/to/bash/script", $arg1, $arg2, ...);
This avoids problems if the arguments contain any shell metacharacters.
--
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
>> > ...
>> > > Thanks for the reply - that worked great, however, now it's
>> > > executing so fast that it's running my bourne shell script before
>> > > it is completely written. How would I go about inserting a pause
>> > > for 30 seconds in the
>> perl
>> > > script?
>> > Can't you just do things sequentially instead of waiting an
>> > arbitrary amount of time?
>> > --
>> > --Ed L Cashin | PGP public key:
>> It takes longer for the Bourne Shell to be written to the file then
>> it does for the Perl script to step through the code and run the
>> Bourne Shell, causing the file to be malformed and execute with
>> errors...Any ideas?
> I must not understand what you mean. Usually you don't write the
> Bourne shell script to a file on the fly, but here's an example of
> doing just that sequentially from a perl script:
> #! /usr/bin/perl -w
> use strict;
> &go;
> sub go {
> my $shfile = "/tmp/test-bourne.sh";
> open SHFILE, "> $shfile" or die "Error: could not open $shfile";
> print SHFILE "#! /bin/sh\n"
> . "echo 'hi there!!!'\n";
> close SHFILE;
> chmod 0755, $shfile;
> system $shfile;
> }
> ... and it works just like you'd expect:
> hi there!!!
Perl experts, any ideas?
--
Jason Baugher
Virtual Adept Professional Consulting Services
1406 Adams St.
Quincy, IL 62301
(217) 221-5406
http://baugher.pike.il.us/virtualadept
The Perl script should close() the filehandle when it's done writing theQuote:>I think what he is trying to say is that the Perl program writes to the
>bourne shell file, but the O/S has not finished flushing the data to the
>disk before the Perl program then tries to execute the bourne shell file.
>Therefore the file is not completely written at the time of execution.
>You need something to force it to flush the data to the disk and wait
>until it is done before moving on.
>Perl experts, any ideas?
--
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Hope this helps :)
1. A Solaris 8 (Bourne Shell) Scripting question, regarding a log rotation script
2. IS only Sun's CDROM could support solaris 2.51
3. Execute a sh script under perl and sh: sh script; perl script?
4. Wrapper running on port 25 ?
5. Q: How can I have a shell script call another shell script...
6. non-blocked signal handlers and SA_NODEFER flag
7. Question about using AWK in a BOURNE shell script
8. KDE Child Panel - Buttons don't display
9. question on a bourne shell script using ||
10. sigsegv by process started via bourne shell by perl cgi script on apache
11. help in learning how to do Bourne shell scripts then converting them to csh scripts
12. Problem in Calling a Perl Script from a Bash Script
13. Incomplete output from crontab email: running shell scripts from a perl script