odd_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone. Work has me manually entering employee numbers into an emulation program where I then have a series of key strokes to display whether this person is retired or not. Then the whole process repeats for every employee number on the list. I want to create a script that allows me to input every employee number into an array, loop through each employee number, pipe each number into the emulation program's input, pass the various repetitive keystrokes, and log the emulators output to a list. I'm pretty sure the emulator is written in Java if that matters. I'm looking for suggestions and opinions even sample script if you have the time. I've been goofing around with perl and C for the past few years. The little knowledge I have is in building relatively simple challenge response scripts run through the terminal. I am completely new to piping and passing input/output from other programs or systems besides text edit. Any and all help you can offer is greatly appreciated. Thanks.

Replies are listed 'Best First'.
Re: Pipeing to a java input.
by zentara (Cardinal) on Sep 01, 2011 at 17:32 UTC
    Look at the various IPC modules (Inter Process Communication) . You can try this simple example, but various glitches can occur like needing a pty or something. You should try to run your java program instead of bash, and see what happens.
    #!/usr/bin/perl use warnings; use strict; use IPC::Open3; $|=1; #my $pid=open3(\*IN,\*OUT,\*ERR,'/bin/bash'); # or your java program my $pid=open3(\*IN,\*OUT,0,'/bin/bash'); # set \*ERR to 0 to send STDERR to STDOUT my $cmd = 'date'; #send cmd to bash print IN "$cmd\n"; # assuming your program understands it print IN "l"; print IN "m"; print IN "t"; print IN "\n"; #getresult my $result = <OUT>; print $result;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Pipeing to a java input.
by roboticus (Chancellor) on Sep 01, 2011 at 15:48 UTC

    odd_perl:

    If it's a command-line program, it may be very easy to do the task, but if it's a GUI program it'll be a little trickier. If it's a GUI on Windows, you may want to send keystrokes to the application. I've not done it so I don't have specific module recommendations, but I'd look for something to help you locate the window of interest, and something to let you send keystrokes to that window. I've seen discussions about both topics here on PM, so I think your best bet would be to use Super Search or google to find the appropriate threads.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Pipeing to a java input.
by odd_perl (Initiate) on Sep 02, 2011 at 14:28 UTC
    This is great guys. Thanks, it gets me started in the right direction. I should have specified that it is a GUI program.