当“开始”失败时,如何在新窗口中运行批处理文件?

时间:2018-01-08 22:29:41

标签: batch-file

我试图使用start "" batchfile.bat,但它只会打开一个没有任何标题的默认CMD窗口。 然后我试着用start CMD call batchfile.bat做同样的结果。我也尝试了start "" "%cd%\batchfile.bat",但又失败了。

有没有办法在不使用“call”的情况下打开另一个批处理文件?我希望它能在自己的窗口中打开。

1 个答案:

答案 0 :(得分:0)

使用示例:

名为foo.cmd的文本文件

echo Foo starting
start bar.cmd
pause

名为bar.cmd的文本文件

echo Welcome to bar
pause

这将在新窗口中打开bar.cmd。 您应确保批处理文件位于当前目录中。如果当前目录不是包含bar.cmd的目录,则必须使用完整路径。如果两个批处理文件都在同一目录中,则可以使用:

start %~dp0bar.cmd

请注意,如果您的路径中包含空格,则无效。如果你必须在路径周围加上引号,它会认为它是指定标题栏文本,而不是文件的路径。

要查找其他启动选项,请检查以下输出:

start /? 
  

启动一个单独的窗口来运行指定的程序或命令。

     

开始["标题"] [/ D路径] [/ I] [/ MIN] [/ MAX] [/ SEPARATE | /共享]         [/ LOW | / NORMAL | / HIGH | / REALTIME | / ABOVENORMAL | /低于一般]         [/ NODE] [/ AFFINITY] [/ WAIT] [/ B]         [命令/程序] [参数]

"title"     Title to display in window title bar.
path        Starting directory.
B           Start application without creating a new window. The
            application has ^C handling ignored. Unless the application
            enables ^C processing, ^Break is the only way to interrupt
            the application.
I           The new environment will be the original environment passed
            to the cmd.exe and not the current environment.
MIN         Start window minimized.
MAX         Start window maximized.
SEPARATE    Start 16-bit Windows program in separate memory space.
SHARED      Start 16-bit Windows program in shared memory space.
LOW         Start application in the IDLE priority class.
NORMAL      Start application in the NORMAL priority class.
HIGH        Start application in the HIGH priority class.
REALTIME    Start application in the REALTIME priority class.
ABOVENORMAL Start application in the ABOVENORMAL priority class.
BELOWNORMAL Start application in the BELOWNORMAL priority class.
NODE        Specifies the preferred Non-Uniform Memory Architecture (NUMA)
            node as a decimal integer.
AFFINITY    Specifies the processor affinity mask as a hexadecimal number.
            The process is restricted to running on these processors.

            The affinity mask is interpreted differently when /AFFINITY and
            /NODE are combined.  Specify the affinity mask as if the NUMA
            node's processor mask is right shifted to begin at bit zero.
            The process is restricted to running on those processors in
            common between the specified affinity mask and the NUMA node.
            If no processors are in common, the process is restricted to
            running on the specified NUMA node.
WAIT        Start application and wait for it to terminate.
command/program
            If it is an internal cmd command or a batch file then
            the command processor is run with the /K switch to cmd.exe.
            This means that the window will remain after the command
            has been run.

            If it is not an internal cmd command or batch file then
            it is a program and will run as either a windowed application
            or a console application.

parameters  These are the parameters passed to the command/program.
     

注意:64位不支持SEPARATE和SHARED选项   平台。

     

指定/ NODE允许以某种方式创建进程   利用NUMA系统上的内存局部性。例如,两个过程   通过共享内存可以相互通信   创建以共享相同的首选NUMA节点以便最小化   记忆延迟。它们在同一个NUMA节点分配内存   可以,他们可以在指定的以外的处理器上运行   节点

start /NODE 1 application1.exe
start /NODE 1 application2.exe
     

这两个进程可以进一步限制为特定运行   同一NUMA节点内的处理器。在以下示例中,   application1在节点的低阶两个处理器上运行,而   application2在该节点的下两个处理器上运行。这个   示例假定指定的节点至少有四个逻辑   处理器。请注意,节点号可以更改为任何有效的   该计算机的节点号,无需更改关联   掩模。

start /NODE 1 /AFFINITY 0x3 application1.exe
start /NODE 1 /AFFINITY 0xc application2.exe
     

如果启用了命令扩展,则通过外部命令调用   命令行或START命令更改如下:

     

可以通过文件关联调用非可执行文件   只是       通过键入文件的名称作为命令。 (例如,WORD.DOC会       启动与.DOC文件扩展名关联的应用程序。       有关如何创建这些命令,请参阅ASSOC和FTYPE命令       来自命令脚本的关联。

     

执行32位GUI应用程序时,   CMD.EXE       在返回之前不会等待应用程序终止       命令提示符。如果执行,则不会发生此新行为       在命令脚本中。

     

执行第一个标记为字符串" CMD"的命令行时       没有扩展或路径限定符,那么" CMD"被替换为       COMSPEC变量的值。这可以防止拾取CMD.EXE       从当前目录。

     

执行第一个令牌不包含的命令行时       扩展,然后CMD.EXE使用PATHEXT的值       环境变量,用于确定要查找的扩展名       以什么顺序PATHEXT变量的默认值       是:

    .COM;.EXE;.BAT;.CMD

Notice the syntax is the same as the PATH variable, with
semicolons separating the different elements.
     

搜索可执行文件时,如果没有匹配项   扩展,然后查看名称是否与目录名称匹配。如果   它确实,START命令在该路径上启动资源管理器。如果   从命令行完成,它相当于执行CD / D.   那道路。

相关问题