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

Hi, (I am sure this has been solved a billion times, but I am interested in learning by doing ;-)

For example, if I create a sendmail.exe program that I want to drive from Perl (Win32 now, Linux future). I know I can pass parameters on the command line. This isn't a problem for small things...but the line length, at some point, isn't going to be big enough...

I also see programs like "sort.exe" (Win32) I assume they read from STDIN and the when STDIN is closed? they process all words and spit out a sorted list...right? (Seems like they can effectively read any buffer length...) These types of commands don't allow this: "sort.exe /?"

I have looked at pipe, but it seems like it is going to call fork(), which I am avoiding on Win32...

Is it normal to provide 2 sendmail programs? One that you use from the command line: sendmail -s=subj -b=msg_body

And then one that reads from STDIN? (for the msg_body) ?

Is this the right way to send long messages to a simple external program? (ie no IP communication)

Thanks (hope this makes sense ;-)

Edit kudra, 2002-05-11 Changed title per ntc

  • Comment on Handling long command lines (was: Input to external program)

Replies are listed 'Best First'.
Re: Input to external program
by Zaxo (Archbishop) on May 10, 2002 at 23:37 UTC

    You can call magic open

    open THING, '|-', '/path/to/util.exe', @clargs; print THING for <DATA>; # or some such

    Update: Reply, Have you tried an absolute path to util.exe, as indicated? Can't guarantee anything about w32, but the full path to the executable would help on 'nix. That construction leaves out the shell, which would prevents relative paths from being resolved without luck.

    After Compline,
    Zaxo

      Thanks for the help...I couldn't get it to work ;-(
      (As a reminder, I am on Win32...)

      open (THING, '|-', 'sort.exe'); my @unsorted = qw(bbb aaa ccc eee ddd); print THING "$_ " foreach @unsorted; close (THING); # My assumption is that after I close(), sort.exe knows to start "sort +ing"...
      outputs:
      bbb aaa ccc eee ddd
        I know that the unix "sort" work on lines so perhaps you might need to replace :
        print THING "$_ " foreach @unsorted;
        by
        print THING "$_\n" foreach @unsorted;

        ???

        "sort" reads all the lines and sort them in memory (and using temporary files), then when it receive an EOF on STDIN (your close()) it print out the sorted lines.