我想使用wmic Process call create
在当前工作目录中打开CMD。但是,当我添加"%~dp0"
来指定目录时,以下命令不会输出任何内容。
for /F "tokens=2 delims==; " %%I in ('wmic Process call create "cmd.exe"^,"%~dp0" ^| find "ProcessId"') do echo PID = %%I
据我所知%~dp0
将以\
结尾,所以%~dp0
将会像C:\Users\
。
如果我删除\
,它将起作用。例如:以下命令将起作用。
for /F "tokens=2 delims==; " %%I in ('wmic Process call create "cmd.exe"^,"C:\Users" ^| find "ProcessId"') do echo PID = %%I
如何在动态工作目录中使用wmic Process call create
?
答案 0 :(得分:0)
我找到了解决方案。我必须添加一个尾随点(.
)。
%~dp0
至%~dp0.
for /F "tokens=2 delims==; " %%I in ('wmic Process call create "cmd.exe"^,"%~dp0." ^| find "ProcessId"') do echo PID = %%I
了解更多:How to get the path of a batch script without the trailing backslash in a single command?