cmd 脚本 - set 似乎没有被执行
cmd script - set does not apear to be executed
我正在尝试将服务的路径名放入我的 cmd 脚本中的变量中。当它执行时,我得到一行 set idmsys=C:\Windows\System32\spoolsv.exe 但它实际上并没有设置变量。谁能解释一下为什么?
这是片段:
wmic service spooler get pathname | for /f %%i in ('find /I "spool"') do set idmsys=%%i
如果我之后执行 echo %idmsys% 变量为空。
运行 而不是
for /F "tokens=1" %%i in ('
wmic service spooler get pathname^, SystemName ^| find /I "spool"
') do set "idmsys=%%i"
当命令通过 | batch_command
进行管道传输时,这将实例化一个新的 CMD.exe
实例。 证明:
==>wmic process where "CommandLine like 'wmic%' or CommandLine like 'findstr%' or CommandLine like '%cmd%'" get caption, commandline, ProcessID, ParentProcessID /value | findstr "^"
Caption=cmd.exe
CommandLine="C:\Windows\system32\cmd.exe"
ParentProcessId=3096
ProcessId=4148
Caption=WMIC.exe
CommandLine=wmic process where "CommandLine like 'wmic%' or CommandLine like 'findstr%' o
r CommandLine like '%cmd%'" get caption, commandline, ProcessID, ParentProcessID /value
ParentProcessId=4148
ProcessId=2084
Caption=findstr.exe
CommandLine=findstr "^"
ParentProcessId=4148
ProcessId=4596
==>
在 parallel 甚至 child cmd
实例中对环境所做的任何更改都不会影响 parallel 甚至 parent 一个。 证明:
d:\bat>set idmsys
Environment variable idmsys not defined
d:\bat>cmd /E /V /C cd files ^& set "idmsys=!CD!" ^& set idmsys ^& pause
idmsys=d:\bat\files
Press any key to continue . . .
d:\bat>set idmsys
Environment variable idmsys not defined
d:\bat>
我正在尝试将服务的路径名放入我的 cmd 脚本中的变量中。当它执行时,我得到一行 set idmsys=C:\Windows\System32\spoolsv.exe 但它实际上并没有设置变量。谁能解释一下为什么?
这是片段:
wmic service spooler get pathname | for /f %%i in ('find /I "spool"') do set idmsys=%%i
如果我之后执行 echo %idmsys% 变量为空。
运行 而不是
for /F "tokens=1" %%i in ('
wmic service spooler get pathname^, SystemName ^| find /I "spool"
') do set "idmsys=%%i"
当命令通过 | batch_command
进行管道传输时,这将实例化一个新的 CMD.exe
实例。 证明:
==>wmic process where "CommandLine like 'wmic%' or CommandLine like 'findstr%' or CommandLine like '%cmd%'" get caption, commandline, ProcessID, ParentProcessID /value | findstr "^"
Caption=cmd.exe
CommandLine="C:\Windows\system32\cmd.exe"
ParentProcessId=3096
ProcessId=4148
Caption=WMIC.exe
CommandLine=wmic process where "CommandLine like 'wmic%' or CommandLine like 'findstr%' o
r CommandLine like '%cmd%'" get caption, commandline, ProcessID, ParentProcessID /value
ParentProcessId=4148
ProcessId=2084
Caption=findstr.exe
CommandLine=findstr "^"
ParentProcessId=4148
ProcessId=4596
==>
在 parallel 甚至 child cmd
实例中对环境所做的任何更改都不会影响 parallel 甚至 parent 一个。 证明:
d:\bat>set idmsys
Environment variable idmsys not defined
d:\bat>cmd /E /V /C cd files ^& set "idmsys=!CD!" ^& set idmsys ^& pause
idmsys=d:\bat\files
Press any key to continue . . .
d:\bat>set idmsys
Environment variable idmsys not defined
d:\bat>