Solved

How to exec Dos programs from perl

Posted on 1998-08-15
7
155 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
binary to char / hexadecimal 5 112
SIMPLE Perl Regex 1 158
Add additional column to .csv using Perl. 8 140
Any syntax error for this clone.plscript 6 139
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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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