1

I'm trying to run some pulseaudio operations with ProcessBuilder in Java, e.g. pacmd list-source-outputs on Ubuntu 18.04. When I run the code directly from Intellij it says No PulseAudio daemon running, or not running as session daemon. However, if I go to build/classes/java/main and execute java MyMainClass it works as expected.

I assume that it has something to with how the Intellij terminal is integrated. It doesn't seem to behave the same as the OS terminal (see image). Does anyone have more insights about the Intellij Terminal?

Process p = null;
try {
    p = new ProcessBuilder("pacmd", "list-source-outputs").start();

    printStream(p.getInputStream());
    printStream(p.getErrorStream());

    p.waitFor();
} catch (IOException | InterruptedException e) {
    e.printStackTrace();
}

Both terminals

Edit: My Terminal settings:

Intellij Terminal settings

Linux Terminal

JoschJava
  • 1,152
  • 12
  • 20
  • 1
    Are you sure you are using the same shell in Intellij? This might be helpful to you https://www.jetbrains.com/help/idea/terminal-emulator.html – Alexis Pavlidis Nov 16 '19 at 11:25
  • you can edit the shell from terminal in the settings. Open settings and write terminal. There you see the current shell. – pL4Gu33 Nov 16 '19 at 11:28
  • I added the settings pictures. Are there more options to see whether it is the same? – JoschJava Nov 16 '19 at 11:44

1 Answers1

0

The problem was with pulseaudio. What worked for me was to call

export PULSE_RUNTIME_PATH=/run/user/1000/pulse

before running any pulseaudio/pacmd/pacntl command. The export command doesn't seem to work from runtime. However, you can create a shell file and then execute your commands:

test.sh:

#!/bin/bash
export PULSE_RUNTIME_PATH=/run/user/1000/pulse
pacmd list-source-outputs

In Java:

Runtime.getRuntime().exec("sh test.sh");

Easier handling for dynamic calling:

test.sh:

#!/bin/bash
export PULSE_RUNTIME_PATH=/run/user/1000/pulse
$1

In Java:

Runtime.getRuntime().exec("sh test.sh \"pacmd list-source-outputs\"");

Here is the official answer from Jetbrains:

How do you launch IDE: from terminal via .sh script or from desktop launcher? make sure to try to launch it from terminal via .sh script.

Also try restarting the IDE after starting the pulseaudio or restart the pulseaudio daemon in IDE terminal. Try also these suggestions: https://bbs.archlinux.org/viewtopic.php?pid=1214072#p1214072 https://bbs.archlinux.org/viewtopic.php?pid=1214157#p1214157

Note that after changing the environment it might be needed to restart the IDE.

JoschJava
  • 1,152
  • 12
  • 20