I'm trying to run some external command line program in Mathematica, and I have problem getting the output.
For example,
Import["!echo hello world\nexit\n", "Text"]
(*"hello world"*)
run echo and get the output.
However this doesn't work for me
Import["!g++ -v", "Text"]
I only get an empty line.
In version 10, there is the RunProcess function which seems to work
RunProcess[$SystemShell, "StandardError", "g++ -v
exit
"]
(*
Configured with: --prefix=/Library/Developer/CommandLineTools/usr \
--with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
*)
My question is, can we do the same thing in version 9, using other functions ?
Import["!g++ -v 2>&1", "Text"]and got the G++ version information inside Mathematica. – Sep 12 '14 at 08:23RunProcessinstead ofImport,Runor similar? I would like to use the nice facilities ofRunProcess(like returning an association of exitcode, stdout, stderr), but am unable to figure out how to do it as nothing seems to work, e.g.RunProcess[{"foo", "> file.out"}]. – István Zachar Sep 30 '15 at 08:03RunProcess[ $SystemShell, All, "foo > file.out" ]. – István Zachar Oct 08 '15 at 08:28