当前位置: 动力学知识库 > 问答 > 编程问答 >

Opening a list of processes with cmd parameters from a file

问题描述:

I have a script which will write a file (currently C:\test.txt) of processes (it checks for processes from a pre-defined list).

I then run some other code (not important what gets done here, but part of this is to end these processes).

My problem is, at this point in my script, I need to be able to relaunch the processes that were terminated but load them with the cmd parameters they were runnign with previously.

The test.txt file will look something like this:

"C:\folder1\folder2\application1.exe" param1

"C:\folder1\folder2\folder3\application2.exe" param1 param2

"C:\folder4\application3.exe"

"C:\folder1\folder2\folder3\application4.exe" param1 param2 param3 param4

etc..

I used a for loop to take the lines from the file and try to run them;

for /f "usebackq tokens=1,* delims= " %%C in (C:\test.txt) do (

%%C %%D

)

This woks fine, except that the script waits for the first process to complete (i.e. terminate again), before loading the next one, and these processes will not end!

I tried to use

start %%C %%D

but I loads a new CMD window with the file path, then tries to run the file with the name from %D

Using;

start %%C %%C %%D

does seem to work, but I've no idea why, and I'm sure that its not the right way to do this.

Can anyone explain why this works, and the others do not, and if there is a proper way to do this??

Thanks

网友答案:

The first parameter after start command within quotes is considered as 'Window Title'. Then followed by command and the parameters.

Thats why

start %%C %%D

does not work as %%C which is within quotes is considered window title and tries to run %%D command.

This should also work:

start "" %%C %%D

See:

start /?

Why can't I start programs in the command line without /d? (Windows 7x64)

分享给朋友:
您可能感兴趣的文章:
随机阅读: