Running a batch file from Perl (Activestate perl in Windows)

喜夏-厌秋 提交于 2019-12-05 21:16:39

You need to escape your backslashes inside of double quotes.

my $exe = "C:\\project\\set_env_and_run.bat";
...
my $status = system("$cmd > c:\\tmp\\out.txt 2>&1");

Are you sure the bat file isn't running. I have taken your code, fixed up the paths that don't exist on my machine. I get it to call the batch file

echo In myrun  1=%1  2=%2

And it writes the following to the output file

 In myrun  1="\\Server\share\folder1"  2="D:\output\folder1"

I would say that you should define exe like this:

my $exe = "cmd.exe /c C:\\project\\set_env_and_run.bat";

you could use

 system ("start C:\\project\\set_env_and_run.bat");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!