4
$\begingroup$

I am currently trying to open a terminal in Linux from Mathematica in which the present working directory is given by the Directory[].

My naive attempt

RunProcess[{"gnome-terminal", "--working-directory=" <> Directory[]}]

does not seem to work and returns a standard error "error: XDG_RUNTIME_DIR not set in the environment". I am aware that this might not be a Mathematica specific problem but general answers regarding the same error message did nothelp me much so far.

$\endgroup$
4
  • $\begingroup$ if you have xterm you may be better off to just run that (or any other plain terminal). Gnome in general seems to just make simple things difficult. $\endgroup$
    – george2079
    Commented Jan 15, 2018 at 17:28
  • 2
    $\begingroup$ FWIW, RunProcess[{"open", "-a", "Terminal"}] works on MacOS. $\endgroup$
    – C. E.
    Commented Jan 15, 2018 at 17:31
  • $\begingroup$ Does RunProcess[$SystemShell, All, "gnome-terminal --working-directory=" <> Directory[]] work $\endgroup$ Commented Jan 15, 2018 at 18:19
  • $\begingroup$ @SubaThomas Unfortunately, no. It seems that the problem is really system-dependent. $\endgroup$
    – Sungmin
    Commented Jan 16, 2018 at 11:20

1 Answer 1

3
$\begingroup$

This works:

   RunProcess @ {$SystemShell,"-c",
      StringTemplate["gnome-terminal  -- /bin/bash -c 'cd `dir`; exec /bin/bash'"] @
        <|"dir" -> Directory[]|>}
$\endgroup$
2
  • $\begingroup$ I don't have gnome-terminal but xfce4-terminal. The solution seems to depend on the Linux-flavour. I found no environment variable telling me that xfce4-terminal is the right candidate. In other cases it will be gnome-terminal or something else. $TERM is not the right thing: 1st using it requires an operational bash and 2nd it returns xterm-256color in my case, which is only an indication that the virtual terminal is capable of colour output. $\endgroup$ Commented Oct 16, 2021 at 10:44
  • $\begingroup$ One has to distinguish between RunProcess, which runs a process in a terminal but stops the Mma session until the started process is finished and StartProcess, which returns a ProcessObject. process = StartProcess @ {$SystemShell, "-c", "xfce4-terminal"} opens a terminal window. A subsequent WriteLine[process, "echo hello world"]; however does not write that to this terminal window as I would have expected, nor does it execute that command. - I want to run several programs and tee their output to a file parallel to showing it the terminal. Any idea? $\endgroup$ Commented Oct 16, 2021 at 21:20

Your Answer

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

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