0

I'm trying to write a batch to print through devcon and process the files later.

Here's my code

:: Change working directory to devcon
CD /d C:\Program Files (x86)\Windows Kits\10\Tools\x64
:: List all devices 
devcon findall =USB ^> findallUsb.txt
:: Process each line
FOR /f "tokens=*" %%i IN (findallUsb.txt) do @echo %%i
PAUSE

And here's my output

C:\WINDOWS\system32>CD /d C:\Program Files (x86)\Windows Kits\10\Tools\x64

C:\Program Files (x86)\Windows Kits\10\Tools\x64>devcon findall =USB > findallUsb.txt
No matching devices found.

C:\Program Files (x86)\Windows Kits\10\Tools\x64>FOR /F "tokens=*" %i IN (findallUsb.txt) do @echo %i
The system cannot find the file findallUsb.txt.

C:\Program Files (x86)\Windows Kits\10\Tools\x64>PAUSE
Press any key to continue . . .

It seems that something is going wrong with the caret escape and the greater than character, but I can't figure it out. I obviously run the batch on as admin. When I run from the command line the file is printed correctly. If I omit the print switch, the results are listed correctly.

George P.
  • 140
  • 1
  • 1
  • 7
  • 2
    If you want the content of `devcon findall =USB` to be output to `findallUsb.txt`, you need to remove the caret, `devcon findall =USB > findallUsb.txt`, because you want it to redirect. The code can probably be improved simplified or made more efficient, but for that it would be advisable to tell us exactly what youre wanting to list/echo. – Compo Oct 04 '18 at 14:22
  • I removed the caret and it works fine! I thought that there would be a conflict, because the devcon manual at docs.microsoft mentions the print to file operation with '>'. But I guess they mean you can use the default cout to file, to print the output? I'm trying to remove shadow USB and COM port devices from my work PC. I'm an embedded firmware developer and those pile up. – George P. Oct 05 '18 at 05:31

0 Answers0