1
$\begingroup$

This command works on Windows:

 ReadList["!" <> "echo hello", String]

Assuming the "!" suggests Windows command shell (verified as $SystemShell),

However, I tried the above code in msys.bat which is a Unix-type shell on Windows, and it did not work. How can I do the above operation if it is not a Windows command shell?

Do I need to replace "!" or change $SystemShell somewhere?

I have tried RunProcess (or ReadList) as:

 path = "C:\\MinGW\\msys\\1.0\\msys.bat";   

 RunProcess[path, "StandardOutput", "echo Hello world
            exit
           "]

This opens msys.bat in a new window, and Mathematica keeps running.

$\endgroup$
5
  • $\begingroup$ Perhaps reference.wolfram.com/language/ref/RunProcess.html can be useful. $\endgroup$
    – ilian
    May 14, 2015 at 7:45
  • $\begingroup$ @ilian I tried RunProcess[], did nt work, edited question. $\endgroup$
    – kamuli
    May 14, 2015 at 16:41
  • $\begingroup$ I know that RunProcess only runs executables, not batch files (which must be interpreted by the windows shell). ReadList may have the same problem. $\endgroup$ May 14, 2015 at 16:56
  • $\begingroup$ Maybe the process executed could be cmd /c msys.bat or similar? $\endgroup$
    – ilian
    May 14, 2015 at 16:59
  • $\begingroup$ I'm not very familiar with MinGW, the parent project of MSYS, but my understanding is that msys.bat is only a wrapper for starting a bash shell, but it's not a command interpreter itself, so you can't really pass it shell commands to it. $\endgroup$
    – MarcoB
    May 14, 2015 at 18:42

1 Answer 1

1
$\begingroup$

One approach could be to bypass msys.bat (which I think is primarily concerned with setting up the interactive console) and start the shell executable directly:

In[1]:= shell = "C:\\MinGW\\msys\\1.0\\bin\\bash.exe";
        RunProcess[shell, "StandardOutput", "echo $BASH_VERSION\nexit\n"]

Out[2]= "3.1.23(1)-release"
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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