如何在cmd.exe中使用Windows START?

时间:2016-09-09 21:21:08

标签: windows powershell cmd process

我想设置命令行语句的优先级,例如copy test.txt test2.txt

我找到了Windows START命令,该命令允许设置可执行文件的优先级。 more info

所以我假设我需要将cmd.exe传递给START。

但这不起作用:

START /LOW "mycopy" "cmd.exe copy test.txt test4.txt"

返回:The system cannot find the file cmd.exe copy test.txt test4.txt.

以下打开一个新的空命令窗口,并且不会发生复制:

START /LOW "mycopy" "cmd ""copy test.txt test4.txt"""

以下内容返回Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.,副本不会发生。

START /LOW "mycopy" /B cmd.exe "copy test.txt test4.txt"

单引号,双引号或双引号的其他变体。

如何实现这一目标? (更简单更好:)

首选新命令窗口在执行后自行关闭。

ps,我也对涉及PowerShell的方法持开放态度。

THX!

2 个答案:

答案 0 :(得分:3)

您不需要所有这些引用或start认为这是唯一的参数:命令本身。

这有效:

START /LOW "mycopy" cmd.exe /c copy test.txt test4.txt

注意/c参数,它告诉cmd执行以下命令。

答案 1 :(得分:2)

start语法基本上是:

start cmd_to_run argument to cmd

由于你引用了整个命令,你真的试图运行一个文件名为cmd.exe copy ....的程序,这显然不存在。

只需删除这些引号:

start /low "mycopy" cmd copy test.txt test4.txt
                     ^-command to run
                         ^^^^^^^^^^^^^^^^^^^^^^-- arguments to command

您必须引用命令本身的唯一时间是您是否包含文件名中包含空格的路径,或者程序名称本身包含空格,例如

start c:\program files\foo\bar.exe /hi /mom
      ^^^^^^^^^^---program  (no such file/command)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^ arguments to this bad command

v.s。

start "c:\program files\foo\bar.exe" /hi /mom
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--command
                                     ^^^^^^^^---arguments
相关问题