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

时间:2023-01-19 19:01:04

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?

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

3 个解决方案

#1


34  

This should work:

这应该工作:

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

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

如果第一个参数包含空格,则start命令将第一个参数解释为窗口标题。在这种情况下,这意味着start将整个参数视为标题并且不会看到命令。传递“”(空标题)作为开始的第一个参数修复问题。

#2


9  

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

如果您需要查看执行的输出,请与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 PAUSE after the call or else the window may close instantly.

这将运行file.exe并在同一命令窗口中打印回输出的内容。请记住通话后的暂停,否则窗口可能会立即关闭。

#3


0  

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.exe program, 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

#1


34  

This should work:

这应该工作:

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

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

如果第一个参数包含空格,则start命令将第一个参数解释为窗口标题。在这种情况下,这意味着start将整个参数视为标题并且不会看到命令。传递“”(空标题)作为开始的第一个参数修复问题。

#2


9  

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

如果您需要查看执行的输出,请与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 PAUSE after the call or else the window may close instantly.

这将运行file.exe并在同一命令窗口中打印回输出的内容。请记住通话后的暂停,否则窗口可能会立即关闭。

#3


0  

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.exe program, 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