Why don't you just invoke the batch file via it's fully-qualified-path-name like this?
system("cmd /c \"E:\\MyPerl\\Trial_Scripts\\batch_file.bat\"");
or if you still wish to change directories,
system("cd E:\\MyPerl\\Trial_Scripts && batch_file.bat");
Just don't count on system("cd ...") changing the current directory over the lifetime of the perl script, It only changes directories for that particular instance of system() (or rather, changes directories for the shell that is invoked via system()). As soon as system() returns, perl continues operating in the directory it was in before system() was called.
Or if you wish for a persistent directory change, use perl's own chdir().
update: just cleaned up some nasty formatting error
perl -e '$,=$",$_=(split/\W/,$^X)[y[eval]]]+--$_],print+just,another,split,hack'er
| [reply] [d/l] [select] |
Aha, the real question is asked.
Just do this:
system( "c:/path_to_batfile/mybat.bat" );
No need to call cmd.exe or the like. The shell knows what you want to do with a .bat file. | [reply] [d/l] |
D:\temp>echo echo Batch! > batch.cmd
D:\temp>cd..
D:\>c:
C:\WINNT>perl -e "system q(cd /d d:\\temp & batch.cmd)"
D:\temp>echo Batch!
Batch!
C:\WINNT>
- Use cd /d to to be on the safe side and switch the drive too.
- The cd only applies to the cmd opened by that system (as mentioned by others in this thread.)
- You can also use && instead of the single & for conditional command chaining (think &&/and in Perl.)
Hope that helps
Update: lagging behind... Firefly258 was faster | [reply] [d/l] [select] |