2

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?

3
  • 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. Commented Feb 2, 2016 at 13:13
  • @FrankThomas i do no understand what you mean. the problem is not the dir command. Commented Feb 2, 2016 at 13:27
  • Do you get the same result if using GNU Parallel instead of xargs?
    – Ole Tange
    Commented Feb 6, 2016 at 20:19

1 Answer 1

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.

2
  • it seems that gnuwin32 does not contain parallel :-( Commented Feb 8, 2016 at 9:42
  • Easy to install: wget pi.dk/3; bash 3
    – Ole Tange
    Commented Feb 8, 2016 at 16:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .