如何在 Windows 7/2008 中自动执行 perl 脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5655043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I automate the execution of a perl script in Windows 7/2008?
提问by john smith
I want to execute a perl script every week or so. I've looked at the Task Scheduler but all it does when I select the .pl file and run the task is open the .pl file in notepad++. I then tried having Task Scheduler run a .bat file:
我想每周左右执行一个 perl 脚本。我已经查看了任务计划程序,但是当我选择 .pl 文件并运行任务时,它所做的就是在记事本++中打开 .pl 文件。然后我尝试让 Task Scheduler 运行一个 .bat 文件:
perl goto.pl
It works when I double click it on the desktop (which is where I'm working off of) but only flashes a command prompt screen when I run the task. I googled extensively and many people had this problem and the solution seemed to be "change the permissions" or "add the full pathname to perl.exe and the .pl file without quotes around them". The files and the desktop folder all have full control/permissions and I am an admin account so that doesn't seem to be the solution. My perl script outputs to a text file which I would like to have automatically emailed to a distribution list every week but that's a challenge for later. Thank you.
当我在桌面(这是我工作的地方)上双击它时它可以工作,但是当我运行任务时只闪烁命令提示符屏幕。我在谷歌上进行了广泛的搜索,很多人都有这个问题,解决方案似乎是“更改权限”或“将完整路径名添加到 perl.exe 和 .pl 文件中,不带引号”。文件和桌面文件夹都具有完全控制/权限,我是管理员帐户,因此这似乎不是解决方案。我的 perl 脚本输出到一个文本文件,我希望它每周自动通过电子邮件发送到分发列表,但这是以后的挑战。谢谢你。
回答by Demento
You can change the current working directory in a .bat file, which seems to be the problem.
您可以在 .bat 文件中更改当前工作目录,这似乎是问题所在。
cd c:\directory\of\script\
perl goto.pl
Or you can use full path names, as you suggested yourself in the question.
或者您可以使用完整路径名,正如您在问题中建议的那样。