in reply to Testing Java code

Howdy!

You can run an external command using system (if you don't need to capture the output) or backticks (``) or qx// if you do need to capture the output. It looks like you probably want to use backticks or qx//:

my $output = qx/java .../;

Update: If you capture the output in an array, you get a list of lines instead of one big string...

yours,
Michael

Replies are listed 'Best First'.
Re^2: Testing Java code
by Skeeve (Parson) on Sep 30, 2005 at 05:43 UTC
    And don't forget that you can also use open to start external programs:
    open($javain, "java ... |") or die "...."; while (<$javain>) { #receive the output } close($javain); # # or # open($javaout, "| java ...") or die "...."; foreach (@inputline) { print $javaout $_; #send some input } close($$javaout);
    Key thing is the pipe "|".

    $\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print

      ok I've tried out those methods but when I run the line

       my $output = qx/java MyProgram 50000/

      it outputs the time for that the process runs to the screen but I can't retrieve it

        It's probably writing it to STDERR. Try
        my $output = qx/java MyProgram 50000 2>&1/

        Caution: Contents may have been coded under pressure.

        sounds like you java program is running then but maybe not exiting,

        try a System.exit();