CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
How to Run a .bat file from perl Script

 



koti688
Novice

May 18, 2009, 6:45 AM

Post #1 of 10 (803 views)
How to Run a .bat file from perl Script Can't Post

Hello Friends

I have a .bat file named make.bat in a folder , Can you please tell me how to run that file.

It will result a output folder when i run that bat file manually.

But when i open that .bat file through perl script as a file , it is not doing so.

This is my Script

$makedata="../../FinalSprint07\/fe_svs\/make.bat";
open my $TEST,'<', $makedata or die "'$makedata' file will not open $!";


Please help.
thanks in advance


hem
User

May 18, 2009, 8:06 AM

Post #2 of 10 (797 views)
Re: [koti688] How to Run a .bat file from perl Script [In reply to] Can't Post

Hi

You can use a system or exec command in the perl script

system("xyz.bat");

That should run the batch file


KevinR
Veteran


May 18, 2009, 8:10 AM

Post #3 of 10 (795 views)
Re: [koti688] How to Run a .bat file from perl Script [In reply to] Can't Post


In Reply To
Hello Friends

I have a .bat file named make.bat in a folder , Can you please tell me how to run that file.

It will result a output folder when i run that bat file manually.

But when i open that .bat file through perl script as a file , it is not doing so.

This is my Script

$makedata="../../FinalSprint07\/fe_svs\/make.bat";
open my $TEST,'<', $makedata or die "'$makedata' file will not open $!";


Please help.
thanks in advance


That opens a file for reading, not for running an application. Use system() if the bat file does not return any output back to your perl script. Or use qx{} if it does.

More than likely whatever your bat file does could be done by perl itself and avoid the entire issue.
-------------------------------------------------


koti688
Novice

May 18, 2009, 8:14 AM

Post #4 of 10 (793 views)
Re: [hem] How to Run a .bat file from perl Script [In reply to] Can't Post

But that batch file is in another folder and my scripts are in another folder, how to give the path to that batch file now , please tell me i am a beginner.

Thanks


koti688
Novice

May 18, 2009, 8:22 AM

Post #5 of 10 (792 views)
Re: [koti688] How to Run a .bat file from perl Script [In reply to] Can't Post

system ("cd C:\FinalSprint07\fe_svs");
system ("make.bat");


it says as

The filename, directory name, or volume label syntax is incorrect.
'make.bat' is not recognized as an internal or external command,
operable program or batch file.


FishMonger
Veteran / Moderator

May 18, 2009, 8:33 AM

Post #6 of 10 (790 views)
Re: [koti688] How to Run a .bat file from perl Script [In reply to] Can't Post

Perl has it's own chdir function, so there's no reason to use a system call to cd into anthoer directory.


Quote
C:\test>perldoc -f chdir
chdir EXPR
chdir FILEHANDLE
chdir DIRHANDLE
chdir Changes the working directory to EXPR, if possible. If EXPR is
omitted, changes to the directory specified by $ENV{HOME}, if
set; if not, changes to the directory specified by $ENV{LOGDIR}.
(Under VMS, the variable $ENV{SYS$LOGIN} is also checked, and
used if it is set.) If neither is set, "chdir" does nothing. It
returns true upon success, false otherwise. See the example
under "die".

On systems that support fchdir, you might pass a file handle or
directory handle as argument. On systems that don't support
fchdir, passing handles produces a fatal error at run time.


Use forward slashes in the path.


Code
chdir 'C:/FinalSprint07/fe_svs'; 
system('make.bat');


If your batch file is using full paths, then there's no need to cd into the directory.

Code
system('C:/FinalSprint07/fe_svs/make.bat');


Of course, as Kevin mentioned, you could drop the batch file and do everything in the Perl script.


KevinR
Veteran


May 18, 2009, 8:36 AM

Post #7 of 10 (788 views)
Re: [FishMonger] How to Run a .bat file from perl Script [In reply to] Can't Post

FYI....

http://www.perlmonks.org/?node_id=764614
-------------------------------------------------


FishMonger
Veteran / Moderator

May 18, 2009, 8:45 AM

Post #8 of 10 (786 views)
Re: [KevinR] How to Run a .bat file from perl Script [In reply to] Can't Post


In Reply To


And
http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_24417253.html


KevinR
Veteran


May 18, 2009, 8:55 AM

Post #9 of 10 (781 views)
Re: [FishMonger] How to Run a .bat file from perl Script [In reply to] Can't Post

Ahh.... good old EE.
-------------------------------------------------


$_
Novice

May 18, 2009, 11:50 PM

Post #10 of 10 (770 views)
Re: [koti688] How to Run a .bat file from perl Script [In reply to] Can't Post

Since you know Perl, I'd advice you to download cygwin... you'll have access to a true 'bash', much better than the .bats

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives