O principal problema parece ser o uso de sudo
. Você precisa de gksudo
.
Um exemplo simples de Scala
package com.askubuntu.users.aamir
import scala.sys.process._
object startProcess {
def main(args: Array[String]) {
Process("ls -la")!
}
}
ou com sudo
-rights (você precisa de gksudo
)
package com.askubuntu.users.aamir
import scala.sys.process._
object startProcess {
def main(args: Array[String]) {
Process("gksudo nautilus")!
}
}
e com um pouco mais de Java
package com.askubuntu.users.aamir
object startProcess {
def main(args: Array[String]) {
Runtime.getRuntime.exec(Array[String]("gksudo","nautilus"));
}
}
E aqui está um método Java para iniciar um processo
package com.askubuntu.users.aamir;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class startProcess {
public static void main(String[] args) {
BufferedReader in;
PrintWriter out = new PrintWriter(System.out);
try {
Process p = Runtime.getRuntime().exec(new String[]{"/home/administrator/Desktop/apache-tomcat-8.0.5/bin","-c","echo def123@| sudo -S startup.sh"});
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String text;
while ((text = in.readLine()) != null) {
out.println(text);
out.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
ou
package com.askubuntu.users.aamir;
import java.io.IOException;
public class startProcess {
public static void main(String[] args) {
try {
Runtime.getRuntime().exec(new String[] { "gksudo","nautilus", "/tmp" });
} catch (IOException e) {
e.printStackTrace();
}
}
}