Need help how to run java program
Need help how to run java program
am 29.01.2008 18:25:51 von Bilashi Sahu
Hi,
I am trying to do some QA automation using perl,
running some java program and verifying the results.
How I will run java command in Perl framework.
I will appreciate any kind of hints that will help me
to write automation in perl, (basically how java
program will be invoked using Perl).
regards,
Bilashi Sahu
____________________________________________________________ ________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?categor y=shopping
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Need help how to run java program
am 29.01.2008 21:21:41 von pcapacio
>On Tue, 29 Jan 2008
>Bilashi Sahu wrote:
>I will appreciate any kind of hints that will help me
>to write automation in perl, (basically how java
>program will be invoked using Perl).
>
You could use backticks to execute a system command like so:
my $command = "java -jar $pathLoc$jarName @ARGV";
my @system_out = `$command`;
HTH, Paula
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Need help how to run java program
am 29.01.2008 21:29:33 von Avraham Shapiro
** Low Priority **
Be wary that a fatal exception in the java program if unhandled will be propagated to
your PERL program and kill it, unless you protect the call to java with an eval block. Another alternative
is to spawn the java program as a separate process using SYSTEM or another method.
Avi
>>> "Capacio, Paula J" 01/29/08 3:21 pm >>>
>On Tue, 29 Jan 2008
>Bilashi Sahu wrote:
>I will appreciate any kind of hints that will help me
>to write automation in perl, (basically how java
>program will be invoked using Perl).
>
You could use backticks to execute a system command like so:
my $command = "java -jar $pathLoc$jarName @ARGV";
my @system_out = `$command`;
HTH, Paula
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Need help how to run java program
am 29.01.2008 21:47:45 von ken1
> Be wary that a fatal exception in the java program if unhandled will be propagated to
> your PERL program and kill it, unless you protect the call to java with an eval block.
Huh??? Explain please.
> Another alternative
> is to spawn the java program as a separate process using SYSTEM or another method.
>
Which is basically the way it has to be done - system, backtick, pipe
open etc.
ken1
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Need help how to run java program
am 29.01.2008 21:55:46 von Avraham Shapiro
KiogTG93IFByaW9yaXR5ICoqCgpXaGF0IEkgbWVhbnQgaXMgdGhlIHNlbWFu dGljcyBvZiBiYWNr
dGlja3MgaW5kaWNhdGUgdGhhdCBhbiBleGNlcHRpb24KdGhhdCBvY2N1cnJz IGluIHRoZSBjb21t
YW5kCmVuY2xvc2VkIGJ5IGJhY2t0aWNrcyBhcmUgcHJvcGFnYXRlZCB0byB0 aGUgaW5pdGlhdGlu
ZyBwcm9jZXNzIGF0IHRoZQpwb2ludCBvZiB0aGUgYmFja3RpY2tzLiAgSWYK dGhlIGphdmEgcHJv
Z3JhbSB1bmV4cGVjdGVkbHkgZGllcyB3aXRoIGEgZmF0YWwgZXhjZXB0aW9u IHRoaXMgd2lsbApr
aWxsIHRoZSBQRVJMIHByb2dyYW0gdG9vLAp1bmxlc3MgYW4gRVZBTCBibG9j ayBlbmNsb3NlcyB0
aGUgYmFja3RpY2tzIHRvIHByb3ZpZGUgZXhjZXB0aW9uCmhhbmRsaW5nLiAg CgpIVEgKQXZpCj4+
PiBLZW5uZXRoINeybHdpbmcgPGtlbm5ldGhAb2x3aW5nLnNlPiAwMS8yOS8w OCAzOjQ3IHBtID4+
PgoKPiBCZSB3YXJ5IHRoYXQgYSBmYXRhbCBleGNlcHRpb24gaW4gdGhlIGph dmEgcHJvZ3JhbSBp
ZiB1bmhhbmRsZWQgd2lsbApiZSBwcm9wYWdhdGVkIHRvCj4geW91ciBQRVJM IHByb2dyYW0gYW5k
IGtpbGwgaXQsIHVubGVzcyB5b3UgcHJvdGVjdCB0aGUgY2Fsb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cyBhIHNlcGFyYXRlIHBy b2Nlc3MgdXNpbmcg
U1lTVEVNIG9yCmFub3RoZXIgbWV0aG9kLgo+ICAgCldoaWNoIGlzIGJhc2lj YWxseSB0aGUgd2F5
IGl0IGhhcyB0byBiZSBkb25lIC0gc3lzdGVtLCBiYWNrdGljaywgcGlwZSAK b3BlbiBldGMuCgpr
ZW4xCl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fCkFjdGl2
ZVBlcmwgbWFpbGluZyBsaXN0CkFjdGl2ZVBlcmxAbGlzdHNlcnYuQWN0aXZl U3RhdGUuY29tClRv
IHVuc3Vic2NyaWJlOiBodHRwOi8vbGlzdHNlcnYuQWN0aXZlU3RhdGUuY29t L21haWxtYW4vbXlz
dWJzClRoaXMgZW1haWwgaXMgaW50ZW5kZWQgZm9yIHRoZSByZWNpcGllbnQg b25seS4gIElmIHlv
dSBhcmUgbm90IHRoZSBpbnRlbmRlZCByZWNpcGllbnQgcGxlYXNlIGRpc3Jl Z2FyZCwgYW5kIGRv
IG5vdCB1c2UgdGhlIGluZm9ybWF0aW9uIGZvciBhbnkgcHVycG9zZS4KCl9f X19fX19fX19fX19f
X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCkFjdGl2ZVBlcmwg bWFpbGluZyBsaXN0
CkFjdGl2ZVBlcmxAbGlzdHNlcnYuQWN0aXZlU3RhdGUuY29tClRvIHVuc3Vi c2NyaWJlOiBodHRw
Oi8vbGlzdHNlcnYuQWN0aXZlU3RhdGUuY29tL21haWxtYW4vbXlzdWJz
Re: Need help how to run java program
am 30.01.2008 09:09:11 von ken1
> If
> the java program unexpectedly dies with a fatal exception this will
> kill the PERL program too,
No, that won't happen. If you still claim that, please provide an
example showing this behavior.
ken1
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Need help how to run java program
am 31.01.2008 20:51:11 von Mike Gillis
Avraham Shapiro wrote:
> What I meant is the semantics of backticks indicate that an exception
> that occurrs in the command
> enclosed by backticks are propagated to the initiating process at the
> point of the backticks. If
> the java program unexpectedly dies with a fatal exception this will
> kill the PERL program too,
> unless an EVAL block encloses the backticks to provide exception
> handling.
This isn't true.
$ perl -e 'my $o = `perl -e "die;" 2>&1`; print "I got: $o"; print "Done.\n"'
I got: Died at -e line 1.
Done.
(What I'm doing there is running a perl inside of backticks with a one-line
script, "die;", redirecting stderr to stdout (2>&1), and printing the captured
output.)
If you were correct, I would never get to the "I got:" part of the output.
The only real way to discover the failure of a qx() or backticks is by looking
at $?, which contains the exit code, received signal (if any), and whether or
not there was a core dump. If you don't check $?, you can't differentiate
between errors, nonexistent programs, or successes without any output.
For example:
$ perl -le 'print `thiscommanddoesnotexist`';
$ perl -le 'print `ls emptydirectory`';
$ perl -le 'print `perl -e "die;" 2>/dev/null`'
In the 3rd command, if I didn't redirect stderr to /dev/null, you would see an
error message at the console, but perl itself wouldn't see it -- I just
redirected it to avoid confusion. Many people redirect stderr to /dev/null as
a matter of course, to avoid cluttering the output, and this is what results.
It's always a good idea to check the value of $?.
For more control over a running subprocess, you can open a pipe from it:
my $java_program;
open($java_program, "java -jar /your/jar/here.jar |")
or die("Couldn't run java: $!");
Check 'man perlipc' for all the gritty details!
--
Mike Gillis
Languages Development mikeg@activestate.com
ActiveState Software http://www.activestate.com/languages
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs