0

I am executing my own customized linux from through C as below

C code :

system("service soapserver stop");

here here soapserver is the binary in my linux machine. Same command is executing successfully from putty but from Java when i am trying to get the output of above command its showing none.

Java code : Here soap_systemHelper is the another binary that hits to the corresponding c file function and execute the above command.

Process p = Runtime.getRuntime().exec( "soap_systemHelper 23" );

Please let me know what could be the reason for this that i am not getting any output. I'll be very much thankful for your quick response.

1 Answer 1

2

Use p.getOutputStream() to get an OutputStream from the stdout of the process. You can then read from that stream using standard Java io classes, and if you want, print the output to System.out.

You can also use the methods of the Process class to get error streams and exit values.

Sign up to request clarification or add additional context in comments.

8 Comments

I am using soap_systemHelper 23 command from putty then it executed successfully and stop the soapserver process. but the same thing i executed from java gives not outout with no error means soapserver process still running. below is the java code :Process p = Runtime.getRuntime().exec(“soap_systemHelper 23" ); InputStream inStream = p.getInputStream(); InputStreamReader inReader = new InputStreamReader(inStream); BufferedReader br = new BufferedReader(inReader);
when i execute Runtime.getRuntime().exec("service soapserver stop"), it shows permission denied error for executing "service" but other customized commands executed in in the same way like i have another command (/usr/vm/bin/startnpm) in my c code . this command executed successfully from java code .
Is soap_systemHelper an executable binary? Or a script? If the latter, perhaps you can try to run the script interpreter with that as the argument? Finally, have you tried using the full path name to the variable? The Java Runtime class might not be setting the path in the environment. Finally, do you need to be a privileged user to run the command? If so you will need to use sudo and visudo to allow running sudo without a password.
soap_systemHelper is a binary. I have not tried the command "service soapserver stop" using full path name
You will get a permission denied when running service because it is owned by root, and (I assume) you are running the JVM as an unprivileged user.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.