Hi Gurus:
Im writing some perl that will execute an interactive command at some point in the code. The command is proprietary, but functions something like the sqlplus command, ie it pauses while connecting to a db, and gives a prompt. Between executing commands, there is typically a pause in which no input can be issued. Normally, I would use Expect to do this, but the system is in production, and the customer will not let me install new perl modules on it.
I was going to do this....
$|=1;
$N_CONS = "/usr/bin/ncons";
open (CONS, "| $N_CONS");
sleep 5;
print CONS "config execute test.cfg \n";
sleep 5;
print CONS "config save \n";
sleep 5;
print CONS "quit \n";
sleep 5;
close (CONS);
As I suspected, even with
sleep () between the
print statements, the commands get run too quickly to be processed by the called command. In fact, it generally closes the filehandle before it even gets to run the "quit" piece, leaving the script hanging until I send it a SIGTERM. Setting
$|=1 doesnt help either. Any suggestions?
-chris
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.