Solved

How to exec Dos programs from perl

Posted on 1998-08-15
7
157 Views
Last Modified: 2010-03-05
How does i call a msdos command from perl, and then wait for the command to end and the result to return to my perl program?
CYA. Martin.
0
Comment
Question by:freak022398
  • 3
  • 2
  • 2
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1203535
$result = `command`;
0
 

Author Comment

by:freak022398
ID: 1203536
I just got the script to start the exe file using the
system ("command"); function.
But how do i get the results from the program in the perl script?

0
 
LVL 84

Expert Comment

by:ozo
ID: 1203537
#If by result, you mean the exit code,
$exitcode=system ("command");
#if by result, you mean the stdout:
$output=`command`;
#or
$output=qx"command";
#or
open(COMMAND,'command|');
$output = join'',<COMMAND>;
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 7

Accepted Solution

by:
yoren earned 100 total points
ID: 1203538
Actually you can get both types of result:

$command = "del *.*";

open(COMMAND,"$command|") or die "Error executing $command: $!";
$output = join("",<COMMAND>);
close(COMMAND); # Wait for the command to finish

$exitcode = ($? >> 8); # Exit code of zero usually means success, 1 usually failure

0
 

Author Comment

by:freak022398
ID: 1203539
Great! Just what i needed to get that finished.
Thanks.
CYA. Martin.
0
 

Author Comment

by:freak022398
ID: 1203540
Ups, sorry for the delay, i thought i had graded you :(
At least i made it before you got auto graded.
CYA.

0
 
LVL 7

Expert Comment

by:yoren
ID: 1203541
You're welcome.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl script to parse log and delete the file 17 176
Perl script to parse xml file 2 125
remove duplicates from the csv file 13 113
ppm conversion to curl on a module install 8 85
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question