php 在批处理文件中运行带有参数的exe文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23112377/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:30:20  来源:igfitidea点击:

Run exe file with parameters in a batch file

phpwindowsbatch-filescheduled-tasks

提问by user1421214

Please have a look at my batch file.

请看看我的批处理文件。

echo off
start "c:\program files\php\php.exe D:\mydocs\mp\index.php param1 param2"

but it isn't working. Any ideas how do I get it working?

但它不起作用。任何想法如何让它工作?

回答by nobody

This should work:

这应该有效:

start "" "c:\program files\php\php.exe" D:\mydocs\mp\index.php param1 param2

The startcommand interprets the first argument as a window title if it contains spaces. In this case, that means startconsiders your whole argument a title and sees no command. Passing ""(an empty title) as the first argument to startfixes the problem.

如果start第一个参数包含空格,该命令会将第一个参数解释为窗口标题。在这种情况下,这意味着start将您的整个论点视为标题并且看不到命令​​。传递""(空标题)作为start解决问题的第一个参数。

回答by Scopperloit

If you need to see the output of the execute, use CALLtogether with or instead of START.

如果您需要查看执行的输出,请CALL与 或 代替 一起使用START

Example:

例子:

CALL "C:\Program Files\Certain Directory\file.exe" -param PAUSE

CALL "C:\Program Files\Certain Directory\file.exe" -param PAUSE

This will run the file.exe and print back whatever it outputs, in the same command window. Remember the PAUSEafter the call or else the window may close instantly.

这将运行 file.exe 并在同一个命令窗口中打印回它输出的任何内容。记住PAUSE调用后,否则窗口可能会立即关闭。

回答by álvaro González

Unless it's just a simplified example for the question, my advice is that drop the batch wrapper and schedule PHP directly, more specifically the php-win.exeprogram, which won't open unnecessary windows.

除非这只是问题的一个简化示例,否则我的建议是删除批处理包装器并直接调度 PHP,更具体地说是php-win.exe程序,它不会打开不必要的窗口。

Program: c:\program files\php\php-win.exe
Arguments: D:\mydocs\mp\index.php param1 param2

Otherwise, just quote stuff as Andrew points out.

否则,只需引用安德鲁指出的内容。



In older versions of Windows, you should be able to put everything in the single "Run" text box (as long as you quote everything that has spaces):

在旧版本的 Windows 中,您应该能够将所有内容放在单个“运行”文本框中(只要您引用所有包含空格的内容):

"c:\program files\php\php-win.exe" D:\mydocs\mp\index.php param1 param2