xargs misinterprets backslashes on windows

1

I am using gnuwin32 utilities on windows 7.

I want to pipe a file list to xargs to remove the files.

but if i pipe normal windows paths in then xargs interprets and removes the backslashes

dir /B /S c:\windows\system32\*.sys | head | xargs echo

results in the following input to xargs

c:\windows\system32\clfs.sys
c:\windows\system32\win32k.sys
c:\windows\system32\drivers\1394bus.sys
c:\windows\system32\drivers\1394ohci.sys
c:\windows\system32\drivers\acpi.sys
c:\windows\system32\drivers\acpipmi.sys
c:\windows\system32\drivers\adp94xx.sys
c:\windows\system32\drivers\adpahci.sys
c:\windows\system32\drivers\adpu320.sys
c:\windows\system32\drivers\afd.sys

that then prints

c:windowssystem32clfs.sys c:windowssystem32win32k.sys c:windowssystem32drivers1394bus.sys c:windowssystem32drivers1394ohci.sys c:windowssystem32driversacpi.sys c:windowssystem32driversacpipmi.sys c:windowssystem32driversadp94xx.sys c:windowssystem32driversadpahci.sys c:windowssystem32driversadpu320.sys c:windowssystem32driversafd.sys

with the backslashes removed. So instead of simply outputting the input on the command line it parses and interprets the strings that I think it should not do.

How to work around this?

vlad_tepesch

Posted 2016-02-02T11:48:54.243

Reputation: 211

quote the file path. this is the standard approach to unescaping escape characters. I'm surprised however that you are not having issues with the switches in dir. – Frank Thomas – 2016-02-02T13:13:41.637

@FrankThomas i do no understand what you mean. the problem is not the dir command. – vlad_tepesch – 2016-02-02T13:27:28.130

Do you get the same result if using GNU Parallel instead of xargs? – Ole Tange – 2016-02-06T20:19:59.860

Answers

0

I can reproduce your findings on GNU Linux. Here the solution is to use GNU Parallel instead. So try using GNU Parallel:

dir /B /S c:\windows\system32\*.sys | head | parallel echo

It has been tested on CygWin, so it might just work on gnuwin32, too.

Ole Tange

Posted 2016-02-02T11:48:54.243

Reputation: 3 034

it seems that gnuwin32 does not contain parallel :-( – vlad_tepesch – 2016-02-08T09:42:59.013

Easy to install: wget pi.dk/3; bash 3 – Ole Tange – 2016-02-08T16:15:41.437