6
$\begingroup$

I'd like to emulate

ls -tlra | grep <search term>

in Wolfram. I have tried

Module[{},
  SetDirectory[dir]
  RunProcess[{"ls", "-tlra", "|", "grep", <searchTerm>}, "StandardOutput"]
]

which doesn't seem to work. Is there a way to use the "pipe" operator when shelling out commands in Wolfram?

$\endgroup$
  • 1
    $\begingroup$ Try prepending "bash","-c" as I show in this answer. $\endgroup$ – Tim Laska Sep 10 at 16:35
12
$\begingroup$

For example:

RunProcess[{"bash", "-c", 
  "ls -ltr | grep wolf "}, "StandardOutput", 
 ProcessDirectory -> $InstallationDirectory]
(* "-rwxr-x---+ 1 Administrators None  551360 Apr  8 09:51 \
wolfram.exe
-rwxr-x---+ 1 Administrators None 2390464 Apr  8 09:52 \
wolframscript.exe *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.