WMIC: how to use “process call create” with the current working directory

假装没事ソ 提交于 2021-01-29 11:15:04

问题


I want to use wmic Process call create to open a CMD at current working directory. But when I add "%~dp0" to specify directory the following command output nothing.

for /F "tokens=2 delims==; " %%I in ('wmic Process call create "cmd.exe"^,"%~dp0" ^| find "ProcessId"') do echo PID = %%I

As I know %~dp0 will end with \, so %~dp0 will be like C:\Users\.

If I remove \ It will works. E.g: The following command will work.

for /F "tokens=2 delims==; " %%I in ('wmic Process call create "cmd.exe"^,"C:\Users" ^| find "ProcessId"') do echo PID = %%I

How can I use wmic Process call create with dynamic working directory?


回答1:


I found the solution. I have to add a trailing dot (.).

%~dp0 to %~dp0.

for /F "tokens=2 delims==; " %%I in ('wmic Process call create "cmd.exe"^,"%~dp0." ^| find "ProcessId"') do echo PID = %%I

Read more: How to get the path of a batch script without the trailing backslash in a single command?



来源:https://stackoverflow.com/questions/51353917/wmic-how-to-use-process-call-create-with-the-current-working-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!