简体   繁体   English

批处理脚本在Windows 10 Pro上运行,但不在Surface Pro 4上运行

[英]Batch Script runs on Windows 10 Pro but not on Surface Pro 4

I have a batch script that has been happily running fine on our desktops and laptops running both W8.1 and W10 for some time now. 我有一个批处理脚本,该脚本在运行W8.1和W10的台式机和笔记本电脑上运行了一段时间已经可以正常运行了。 The same exact script can't get past this last line of code without claiming "syntax error" 如果不声明“语法错误”,则相同的确切脚本无法通过最后一行代码

if not exist C:\epic\tablet.txt if not exist C:\epic\laptop.txt (
    @set SVPATH="D:\EPIC\Backup\"
) else (
    @set SVPATH="C:\EPIC\Backup\"
)

@echo %SVPATH%

if not exist %SVPATH% mkdir %SVPATH%

There are a bunch of lines of code after it, that again the laptops and desktops have no issues with, but the tablet can't get past that last line. 后面有很多代码行,笔记本电脑和台式机也没有问题,但是平板电脑无法越过最后一行。 It just gives the following output and then exits the script: 它仅给出以下输出,然后退出脚本:

ECHO is on.
>The syntax of the command is incorrect
>if not exists  mkdir
>

It looks like it's not actually setting a value to SVPATH, but as I said, this works just fine on both desktop and loptops running windows 8.1 and windows 10. It's only the Surface Pro 4s that have the issue, and it's not just one, it's all that we have tested. 看来实际上并没有为SVPATH设置值,但是正如我说的那样,这在运行Windows 8.1和Windows 10的台式机和笔记本电脑上都可以正常工作。这只是Surface Pro 4s遇到的问题,而不仅仅是一个问题,这就是我们测试过的一切。

I don't have a Surface Pro, but try following batch code: 我没有Surface Pro,但是请尝试使用以下批处理代码:

@echo off
set SVPATH=C:\EPIC\Backup
if not exist C:\epic\tablet.txt if not exist C:\epic\laptop.txt set SVPATH=D:\EPIC\Backup
echo %SVPATH%
md %SVPATH% 2>nul
set SVPATH=

It is required to enclose file/folder argument strings within " on containing a space or one of these characters &()[]{}^=;!'+,`~ which is not the case here. So the double quotes can be safely omitted in this batch file. 必须将文件/文件夹参数字符串包含在" ,其中必须包含空格或以下字符之一( &()[]{}^=;!'+,`~ ,此处不是这种情况。因此,双引号可以是安全地在此批处理文件中省略。

The environment variable SVPATH is in any case defined with this code independent on existence of the two files C:\\epic\\tablet.txt and C:\\epic\\laptop.txt . 在任何情况下,都使用此代码定义环境变量SVPATH ,而与两个文件C:\\epic\\tablet.txtC:\\epic\\laptop.txt

It is recommended to assign a file/folder string to an environment variable always without double quotes to an environment variable and instead reference the environment variable value as is or concatenated with other environment variable value references or with fixed strings enclosed within double quotes. 建议始终为环境变量分配文件/文件夹字符串,而对环境变量始终不加双引号,而应直接引用环境变量值或与其他环境变量值引用或串联在双引号内的固定字符串串联。

@echo off
set "SVPATH=C:\EPIC\Backup"
if not exist "C:\epic\tablet.txt" if not exist "C:\epic\laptop.txt" set "SVPATH=D:\EPIC\Backup"
echo %SVPATH%
md "%SVPATH%" 2>nul
set SVPATH=

Please note that recommended syntax set "Variable=Value" requires enabled command extensions. 请注意,建议的语法set "Variable=Value"需要启用的命令扩展名。 For more details about this syntax read the answer on Why is no string output with 'echo %var%' after using 'set var = text' on command line? 有关此语法的更多详细信息,请阅读以下答案: 为什么在命令行上使用“ set var = text”后,没有使用“ echo%var%”输出字符串?

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

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