简体   繁体   English

Windows批处理多行命令?

[英]windows batch multiline command?

Can someone please tell me what in the following command line not correct is? 有人可以告诉我以下命令行中不正确的是什么吗?

${WORKSPACE} = C:\jenkins\workspace\compile-job

cmd.exe /s /c START /b /BELOWNORMAL
mkdir C:\jenkins\workspace\old
move /Y %WORKSPACE%\* C:\jenkins\workspace\old
rmdir /q /s C:\jenkins\workspace\old

Plenty. 好多

  1. ${WORKSPACE} = ... is neither cmd nor PowerShell syntax, it's nothing sensible. ${WORKSPACE} = ...既不是cmd也不是PowerShell语法,这没有任何意义。 Use 采用

     set WORKSPACE=C:\\jenkins\\workspace\\compile-job 

    instead. 代替。

  2. You can have multi-line commands by ending the line before with ^ . 您可以通过在^之前结束行来获得多行命令。 However you want to execute three commands instead of just one. 但是,您要执行三个命令,而不仅仅是一个。 One option would be to write a batch file to execute (certainly the cleanest approach). 一种选择是编写一个批处理文件以执行(肯定是最干净的方法)。 But since you already have one, you can get clever: 但是,由于您已经拥有一个,因此可以变得更聪明:

     if not %1==x ( START "" /b /BELOWNORMAL %0 x goto :eof ) set WORKSPACE=C:\\jenkins\\workspace\\compile-job mkdir C:\\jenkins\\workspace\\old move /Y %WORKSPACE%\\* C:\\jenkins\\workspace\\old rmdir /q /s C:\\jenkins\\workspace\\old 

    This will execute the batch file again but with an argument and within the batch we look whether that argument is present and do the work or not. 这将再次执行批处理文件,但带有一个参数,并且在批处理中,我们查看该参数是否存在并进行工作。

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

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