4

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.

Sungmin
  • 2,285
  • 15
  • 23

1 Answers1

3

This works:

   RunProcess @ {$SystemShell,"-c",
      StringTemplate["gnome-terminal  -- /bin/bash -c 'cd `dir`; exec /bin/bash'"] @
        <|"dir" -> Directory[]|>}
Rolf Mertig
  • 17,172
  • 1
  • 45
  • 76
  • 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. – Adalbert Hanßen Oct 16 '21 at 10:44
  • 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? – Adalbert Hanßen Oct 16 '21 at 21:20