I need to run my program as root. I looked at this question and it works somewhat. I need to use stdin and using the bash script doesn't seem to accept stdin. I am using Eclipse and Ubuntu. Any ideas? This also causes problems for other Java programs as they don't accept stdin either.
If you run this code:
import java.io.IOException;
public class Test {
public static void main(String[] args) {
while (true) {
try {
System.out.print((char) System.in.read());
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
And they you type stuff into the Console and hit enter, it outputs what you typed in.
When I use the bash script:
#!/bin/bash
# file: /usr/lib/jvm/java-8-oracle/bin/java
# descr: Starter for jdk. Runs jdk as root when
# cmd-line-arg "--run-as-root" is specified.
#
jre="/usr/lib/jvm/java-8-oracle/bin/java.ori"
run_as_root=false
args=
# Filter command-line argument
for arg in "$@"
do
case "$arg" in
--run-as-root) run_as_root=true
;;
*) args="$args $arg"
;;
esac
done
# Remove leading whitespaces
args=$(echo $args | sed -e 's/^[ \t]*//')
if $run_as_root
then
echo "WARNING: Running as root!"
gksu "$jre $args"
else
$jre $args
fi
I get a bunch of weird characters and when I remove the char cast, I get -1, meaning end of stream.