Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using system(); to run a prescibed command 4

Status
Not open for further replies.

charlesy

Programmer
Aug 3, 1999
26
AU
I am trying to use the system(); command to execute this<br>system('echo &quot;FRPO R3, 01; FRPO L1, $currentL1; FRPO L2, $currentL2; FRPO L3, $c<br>urrentL3; FRPO L4, $currentL4; FRPO R3 00;&quot; ¦ lp -d PR0_KYO -o nobanner');<br><br>These characters tell a Kyocera printer some alignment information.<br><br>It looks like this running from the prompt<br>echo &quot;FRPO R3, 01; FRPO L1, 01; FRPO L2, 00; FRPO L3, 01; FRPO L4, 25; FRPO R3 00;&quot; ¦ lp -d PR0_KYO -o nobanner<br><br>I cannot seem to be able to tell the system()<br>function that what is between the '' is the command to send to the shell but then have the printer understand that what is in the &quot;&quot; is the pre-scribed command<br><br>much obliged
 
The 'single-quotes'(apostrophes) prevent evaluation of $currentLn's, so they are passed to the printer as-is.&nbsp;&nbsp;You will have to use only &quot;double-quotes&quot; for this.<br>
 
like this<br><br><FONT FACE=monospace><b><br>system(&quot;echo \&quot;FRPO R3, 01; FRPO L1, $currentL1; FRPO L2, $currentL2; FRPO L3, $currentL3; FRPO L4, $currentL4; FRPO R3 00;\&quot; ¦ lp -d PR0_KYO -o nobanner&quot;);<br></font></b><br><br> <p>Mike<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Hello
I have a problem regarding perl5 the installation , and perl5 run the program .
I have a windows ME and I am how s the install the perl5 and give suggestion the how’s the program run.
 
Hello
I have a problem regarding perl5 the installation , and perl5 run the program .
I have a windows ME and I am how s the install the perl5 and give suggestion the how’s the program run.
mail to me (prem12july@hotmail.com)...
 
hello is1

If you go to you can download the Perl installation for free.

You may well need to install the new version of windows installer first (MSI) and this is well worth doing.
Mike
________________________________________________________________________________

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
And by the way: get rid of Windows ME. I have it at home and I can't stand it. It's the most pathetic OS ever. EVER!!!!!! I have to reboot several times an evening if I'm debugging a Perl script. I HATE IT! Moving to Linux soon. :D

Oh and uh, Mike, why didn't you direct that poor young man to use the qq// operator?

system(qq/echo &quot;FRPO R3, 01; FRPO L1, $currentL1; FRPO L2, $currentL2; FRPO L3, $currentL3; FRPO L4, $currentL4; FRPO R3 00;&quot; ¦ lp -d PR0_KYO -o nobanner/);

It's much more useful in the long run to choose your own quotes!

Hey Mike: know anything about Ruby?

--jim

 
I don't like qq//, I think it's a bit naff..... In fact, that's the first time I've ever typed it - probably the last as well.

Ruby: No, I don't sorry. It seems to be well thought of though; from comments on perl5-porters it was one of the things that irritated people enough to get started on Perl6. Mike
________________________________________________________________________________

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Is there a way to capture any error codes resulting from using they system() command?
 
If I was you I'd not use the system() function, and use the back-ticks (graves-accents) instead. They execute their contents as from the command line, and return a list which is the resulting output from the system.

Example:
@directory_listing = `ls -l`;

That's what I normally do when I care about capturing output.

--jim
 
You can use the eval function to catch errors

eval {
system(qq/echo &quot;FRPO R3, 01; FRPO L1, $currentL1; FRPO L2, $currentL2; FRPO L3, $currentL3; FRPO L4, $currentL4; FRPO R3 00;&quot; ¦ lp -d PR0_KYO -o nobanner/);
}
#Eval dumps error to this var $@
if ($@){ send error message or jump to some other action

}

Never tried this on a system call but should work
 
No, eval does not work here, I think because as far as perl goes, the system command executed ok. Instead you should
try:
my $return_code= 0xfff & system (&quot;$systemcommand&quot;);
$return_code=0 is no error. You can look up the rest of the story in teh Camel book, p. 230

svar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top