0

I'm trying to get process id of executable that needs series of commands redirected from file, adapted from this answer:

https://stackoverflow.com/a/27595129/1140698

for /f "tokens=2 delims==; " %%A in (
  'wmic process call create "'%exe%' ^< '%arg1%'" ^| find "ProcessId"'
) do set "PID=%%A"
echo "%PID%"

where %arg1% is path to .txt file containing commands needed for automation of simulations for some naval architecture software.

The goal of this is to run 2 sets of commands in parallel so each instance of .bat script must kill it's own process(for some other reasons task kill is necessary).

Error occurs somewhere here:

wmic process call create "'%exe%' ^< '%arg1%'

so the question is, is it possible and how to redirect commands from file in wmic.

Dominique
  • 16,450
  • 15
  • 56
  • 112
im-i0dum
  • 474
  • 1
  • 5
  • 13
  • 1
    `wmic process call create 'cmd /C ""%exe%" < "%arg1%""'`? – aschipfl Apr 30 '19 at 13:57
  • As the linked answer specifically states, "The content of the quoted arguments can contain pretty much anything except for double quote or comma.", can you please confirm the exact content of `%arg1%`? – Compo Apr 30 '19 at 13:57
  • If the arguments are in a file as opposed to string values of e.g. `%arg1%`, you could alternatively read that file first, _(using perhaps `Set /P` or a `For` loop)_, and generate the args for use like `"%arg1%" "%arg2%" "%arg3%" "%arg4%"`. – Compo Apr 30 '19 at 14:10
  • It might help if you were to tell us what error is occurring, and why you nominate that code. I suspect that the `wmic` output isn't what you expect or see on the screen if you execute it from the prompt. `wmic` has a habit of issuing [CR] characters at unexpected points, so `ProcessId` may not necessarily appear in the same logical line as the reported number. I'd send the output of the `wmic` command to a file and then examine that file using a hex-editor. Take note of the precise sequence of bytes it generates to create the screen display. – Magoo Apr 30 '19 at 15:21

0 Answers0