scripting - How do I recover STDIN from a perl script that was called from a csh script? -


I have a terrible nested script structure that I keep from time to time the user takes input from the keyboard and I By default, the script's structure looks like this:

  • cmd1.csh takes 3 line input and then calls cmd2.csh Then returns normally
  • cmd2.csh call cmd3
  • cmd3.pl takes 1 input line and Normally exits.

Unfortunately, I can not permanently replace any of these scripts, so whatever I can do, I did it as a cover around the whole script series. Have to go

I have tried many variations of the following Perl script, but maybe I do not just kill the magic combination of quote and escape:

  $ cmd = "echo 'a \\ b \\ c \\ d \\ e \\ f '| ~ / pltest / cmd1.csh "; System_tcsh subsystem_tcsh {@args = ("tcsh", "-c", shift); Return system (@args); }  

The problem is that once cmd3.pl is called once and d is read, either the second call is read by second call cmd3.pl or cmd2.csh goes. Multiple reading works well in Cmd3.pl and more items are read from STDIN, but once the CMD 3. calls for the first time on completion, STDIN is empty (or in some way absent stage) .

What happens to STDIN when the Perl script returns and is there any way to use this type of input like Perl or something else?

Thanks in advance.

I created the conditions to reproduce the problem, but all went well :

caller.pl:

  #! / Usr / bin / perl $ cmd = "echo 'a \\ b \\ c \\ d \\ e \\ f' | ~ / doc / answer / src / pltest / cmd1.csh"; Sub system_tcsh {@args = ("TCS", "-C", $ CMD); Return system (@args); } System_tcsh  

cmd1.csh:

  #! / Bin / csh "$ {0} (CMD1) $ argv [echo]" set line1 = $ & lt; Set 2 rows = $ & lt; Set 3 = $ & lt; Setenv lineno 3 echo "cmd1: Read: $ line1 $ line2 $ line3" ./cmd2.csh  

cmd2.csh:

  #! / Bin / csh "$ {0} (CMD2)" $ argv [*] Now running ... "./cmd3.csh ./cmd3.csh set line6 = $  

cmd3.csh:

  #! / Bin / csh # cmd3 set line = $ " $ { 0}: Read: '$ line' " 

Run the test:

  frayser @ gentoo ~ / doc / answer / src / pltest $ ./clall .pl /export/home/frayser/doc/Answers/src/pltest/cmd1.csh(cmd1) cmd1: Read: ABC ./cmd2.csh (CMD2) is now running ... ./ cmd3.csh: Read: 'D' ./cmd3.csh: Read: 'E' ./cmd2.csh: Read: F  

Perhaps you can restrain trouble, or use it to modify A To implement your solution.

- UPDATE
This is an update that reproduces the Perl STDIN problem, and its It provides a work for it.

CMD3 was reported by changing a Pearl version, the result of the problem:

cmd3.pl which changes cmd3.csh :

  #! / Usr / bin / perl # cmd3 $ _ = & lt; STDIN & gt; Chomp (); Print "$ 0: Read: '$ _' \ n";  

Result: Using cmd3.pl . After reading "D", no other input is available.

 . Caller.pl ./cmd1.csh (cm1) cmd1: read: abc ./cmd2.csh(cmd2) is now running ... ./cmd3.pl: Read: 'D' ./cmd3.pl: Read : '' ./cmd2.csh: Read:  

To resolve this, send the line cmd3 to cmd3 (1) The command easily changes:

  #! / Bin / csh "$ {0} (CMD2) $ argv [*] is now running ..." line "./cmd3.pl line | ./cmd3.pl set line6 = $ < The line  is optimized to avoid the overhead "$ {0}: Read: $ line6"  cmd2.csh  command.  
 < Code> #! / Bin / csh resonant "$ {0} (cmd2) $ argv [*] Now running ..." set x = $  "$ {0}: Read: $ line6"  

Updated here CMD2.csh is now output with Pearl Because it was using csh as the final script: stdin was not lost.

  ./Cmd1.csh (CMD1) CMD 1: Read: ABC ./cmd2.csh (CMD2) is now running ... ./ cmd3.pl: Read: 'D' ./cmd3.pl: Read: 'E' ./ CMD 2. Csh: Read: f  

Comments