Small doubt in perl
am 27.09.2007 07:55:59 von anil
Hi,
I need a small help, how shall i call shell script and java
program in the perl?
I am using the following snippet of code,
system("sample.sh");
system("java test");
In the "sample.sh" i have set some environmental variables, but the
environment variables which are set in the sample.sh are not used by
the java pgm.
Is there any other way to achieve this functionality?
Thanks & Regards
Anil.
Re: Small doubt in perl
am 27.09.2007 08:46:10 von unknown
Post removed (X-No-Archive: yes)
Re: Small doubt in perl
am 27.09.2007 09:34:56 von Dummy
anil wrote:
> Hi,
> I need a small help, how shall i call shell script and java
> program in the perl?
>
> I am using the following snippet of code,
>
> system("sample.sh");
> system("java test");
Open two xterms (or your favourite terminal program) and run "sample.sh" in
one and "java test" in the other. This is essentially what you are doing there.
> In the "sample.sh" i have set some environmental variables, but the
> environment variables which are set in the sample.sh are not used by
> the java pgm.
How do you set them?
> Is there any other way to achieve this functionality?
open SHELL, '>>', 'sample.sh' or die "Cannot open 'sample.sh' $!";
print SHELL "java test\n";
close SHELL;
system( '/bin/sh', 'sample.sh' ) == 0 or die "system '/bin/sh sample.sh'
failed: $?";
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Re: Small doubt in perl
am 27.09.2007 09:35:50 von Dave Weaver
On Wed, 26 Sep 2007 22:55:59 -0700, anil wrote:
>
> system("sample.sh");
> system("java test");
>
> In the "sample.sh" i have set some environmental variables, but the
> environment variables which are set in the sample.sh are not used by
> the java pgm.
perldoc -q environ
Re: Small doubt in perl
am 27.09.2007 12:12:38 von Michele Dondi
On Wed, 26 Sep 2007 22:55:59 -0700, anil
wrote:
>Subject: Small doubt in perl
http://perlmonks.org/?node_id=444996
>system("sample.sh");
>system("java test");
>
>In the "sample.sh" i have set some environmental variables, but the
>environment variables which are set in the sample.sh are not used by
>the java pgm.
>
>Is there any other way to achieve this functionality?
system qw/sh -c/ => 'sample.sh; java test';
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: Small doubt in perl
am 28.09.2007 07:14:44 von anil
On Sep 27, 12:34 pm, "John W. Krahn" wrote:
> anil wrote:
> > Hi,
> > I need a small help, how shall i call shell script and java
> > program in the perl?
>
> > I am using the following snippet of code,
>
> > system("sample.sh");
> > system("java test");
>
> Open two xterms (or your favourite terminal program) and run "sample.sh" in
> one and "java test" in the other. This is essentially what you are doing there.
>
> > In the "sample.sh" i have set some environmental variables, but the
> > environment variables which are set in the sample.sh are not used by
> > the java pgm.
>
> How do you set them?
>
> > Is there any other way to achieve this functionality?
>
> open SHELL, '>>', 'sample.sh' or die "Cannot open 'sample.sh' $!";
> print SHELL "java test\n";
> close SHELL;
> system( '/bin/sh', 'sample.sh' ) == 0 or die "system '/bin/sh sample.sh'
> failed: $?";
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall
Thank You very much for ur valuable replies......
Re: Small doubt in perl
am 28.09.2007 07:36:04 von anil
On Sep 27, 12:34 pm, "John W. Krahn" wrote:
> anil wrote:
> > Hi,
> > I need a small help, how shall i call shell script and java
> > program in the perl?
>
> > I am using the following snippet of code,
>
> > system("sample.sh");
> > system("java test");
>
> Open two xterms (or your favourite terminal program) and run "sample.sh" in
> one and "java test" in the other. This is essentially what you are doing there.
>
> > In the "sample.sh" i have set some environmental variables, but the
> > environment variables which are set in the sample.sh are not used by
> > the java pgm.
>
> How do you set them?
>
> > Is there any other way to achieve this functionality?
>
> open SHELL, '>>', 'sample.sh' or die "Cannot open 'sample.sh' $!";
> print SHELL "java test\n";
> close SHELL;
> system( '/bin/sh', 'sample.sh' ) == 0 or die "system '/bin/sh sample.sh'
> failed: $?";
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall
Hi john,
Thanks for your reply, but your method is corrupting the
sample.sh, I don't want to corrupt the sample.sh, because this perl
program i have to execute several times, then that java program runs
several times..which degrades the performance of my program.
Thanks
Anil.
Re: Small doubt in perl
am 28.09.2007 17:19:24 von Ben Morrow
Quoth Michele Dondi :
> On Wed, 26 Sep 2007 22:55:59 -0700, anil
> wrote:
>
> >system("sample.sh");
> >system("java test");
> >
> >In the "sample.sh" i have set some environmental variables, but the
> >environment variables which are set in the sample.sh are not used by
> >the java pgm.
> >
> >Is there any other way to achieve this functionality?
>
> system qw/sh -c/ => 'sample.sh; java test';
This won't work. sample.sh is still run as a subprocess of the shell.
You need to locate the shell used for sample.sh (I'll assume /bin/sh),
and run
system '/bin/sh', -c => '. sample.sh; java test';
Note the '.', which makes the shell run the script in the same process.
It may be better to use
system '/bin/sh', -c => '. sample.sh; exec java test';
which will save a fork.
Ben
Re: Small doubt in perl
am 28.09.2007 18:03:15 von Michele Dondi
On Fri, 28 Sep 2007 16:19:24 +0100, Ben Morrow
wrote:
>> system qw/sh -c/ => 'sample.sh; java test';
>
>This won't work. sample.sh is still run as a subprocess of the shell.
>You need to locate the shell used for sample.sh (I'll assume /bin/sh),
>and run
>
> system '/bin/sh', -c => '. sample.sh; java test';
>
>Note the '.', which makes the shell run the script in the same process.
D'Oh! It's true...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: Small doubt in perl
am 01.10.2007 12:49:16 von anil
On Sep 28, 8:19 pm, Ben Morrow wrote:
> Quoth Michele Dondi :
>
> > On Wed, 26 Sep 2007 22:55:59 -0700, anil
> > wrote:
>
> > >system("sample.sh");
> > >system("java test");
>
> > >In the "sample.sh" i have set some environmental variables, but the
> > >environment variables which are set in the sample.sh are not used by
> > >the java pgm.
>
> > >Is there any other way to achieve this functionality?
>
> > system qw/sh -c/ => 'sample.sh; java test';
>
> This won't work. sample.sh is still run as a subprocess of the shell.
> You need to locate the shell used for sample.sh (I'll assume /bin/sh),
> and run
>
> system '/bin/sh', -c => '. sample.sh; java test';
>
> Note the '.', which makes the shell run the script in the same process.
> It may be better to use
>
> system '/bin/sh', -c => '. sample.sh; exec java test';
>
> which will save a fork.
>
> Ben
For curiosity, Is there any method to run on windows also, suppose we
have sample.bat instead of sample.sh ?
Re: Small doubt in perl
am 01.10.2007 15:12:15 von Michele Dondi
On Mon, 01 Oct 2007 03:49:16 -0700, anil
wrote:
>> This won't work. sample.sh is still run as a subprocess of the shell.
>> You need to locate the shell used for sample.sh (I'll assume /bin/sh),
>> and run
>>
>> system '/bin/sh', -c => '. sample.sh; java test';
>>
>> Note the '.', which makes the shell run the script in the same process.
>> It may be better to use
>>
>> system '/bin/sh', -c => '. sample.sh; exec java test';
>>
>> which will save a fork.
>>
>> Ben
>
>For curiosity, Is there any method to run on windows also, suppose we
>have sample.bat instead of sample.sh ?
Exactly the same except that I don't know whether Win's scripting
language allow for the equivalent of sourcing. If it's just a matter
of setting some environment variables one may avoid a separate shell
script and massage %ENV directly from perl, though.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: Small doubt in perl
am 01.10.2007 16:25:00 von anil
On Oct 1, 6:12 pm, Michele Dondi wrote:
> On Mon, 01 Oct 2007 03:49:16 -0700, anil
> wrote:
>
>
>
> >> This won't work. sample.sh is still run as a subprocess of the shell.
> >> You need to locate the shell used for sample.sh (I'll assume /bin/sh),
> >> and run
>
> >> system '/bin/sh', -c => '. sample.sh; java test';
>
> >> Note the '.', which makes the shell run the script in the same process.
> >> It may be better to use
>
> >> system '/bin/sh', -c => '. sample.sh; exec java test';
>
> >> which will save a fork.
>
> >> Ben
>
> >For curiosity, Is there any method to run on windows also, suppose we
> >have sample.bat instead of sample.sh ?
>
> Exactly the same except that I don't know whether Win's scripting
> language allow for the equivalent of sourcing. If it's just a matter
> of setting some environment variables one may avoid a separate shell
> script and massage %ENV directly from perl, though.
>
> Michele
> --
> {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
> (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
> .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
> 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
I have searched in the net and i found the solution we have to
replace ; with & in the above system command. Thanks for all your
valuable replies...
Re: Small doubt in perl
am 01.10.2007 19:05:38 von Michele Dondi
On Mon, 01 Oct 2007 07:25:00 -0700, anil
wrote:
>> >> system '/bin/sh', -c => '. sample.sh; exec java test';
^
^
[snip]
>I have searched in the net and i found the solution we have to
>replace ; with & in the above system command. Thanks for all your
>valuable replies...
Please note that it probably won't be enough, since I don't expect
.. FILE
to valid syntax there. But of course I may be wrong, and that would
certainly be good for you.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: Small doubt in perl
am 01.10.2007 21:16:38 von Ben Morrow
Quoth Michele Dondi :
> On Mon, 01 Oct 2007 07:25:00 -0700, anil
> wrote:
>
> >> >> system '/bin/sh', -c => '. sample.sh; exec java test';
> ^
> ^
>
> [snip]
> >I have searched in the net and i found the solution we have to
> >replace ; with & in the above system command. Thanks for all your
> >valuable replies...
>
> Please note that it probably won't be enough, since I don't expect
>
> . FILE
>
> to valid syntax there. But of course I may be wrong, and that would
> certainly be good for you.
No, it's not. However, cmd.exe *always* sources .bat files (yes,
cringe... it's the legacy of DOS, which Didn't Do Processes), so
system cmd => '/c' => 'sample.bat& java test';
should work (untested, and possibly
system 'cmd /c "sample.bat& java test"';
may work better).
Ben