简体   繁体   English

Windows Batch 使用管道启动 python 脚本

[英]Windows Batch start python script with pipe

I'm trying to create a batch script or scheduled task that can run this:我正在尝试创建一个可以运行的批处理脚本或计划任务:

pythonw manage.py runserver >nul

This will run if I wrote it from a command prompt, and return me the prompt, but if I try to run it using a batch file or an scheduled task it will open a window and lock itself in that command.如果我从命令提示符编写它,这将运行,并将提示返回给我,但如果我尝试使用批处理文件或计划任务运行它,它将打开一个窗口并将自身锁定在该命令中。 The window I will close adding a final "exit" but it will be locked in the first command unless I kill the process in the task manager.我将关闭窗口,添加最终的“退出”,但除非我在任务管理器中终止进程,否则它将被锁定在第一个命令中。

How can I do this?我怎样才能做到这一点? if it works in the normal cmd why don't work the same way when in a .bat or .cmd file?如果它在普通 cmd 中工作,为什么在 .bat 或 .cmd 文件中不以相同的方式工作?

Ok, after testing more and more I found something that works.好的,经过越来越多的测试,我发现了一些有效的方法。 Sorry for making the Question without searching and testing more.很抱歉在没有搜索和测试的情况下提出问题。

This is what has worked:这是有效的:

CMD /c start "" /B path\to\pythonw.exe path\to\manage.py runserver > nul ^& exit

Inside a .cmd file.在 .cmd 文件中。 Executing the file starts the Django dev webserver properly and a scheduled task that runs that .cmd file also start the server.执行该文件会正确启动 Django 开发网络服务器,并且运行该 .cmd 文件的计划任务也会启动服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM