• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime.getRuntime execute script linux  RSS feed

 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks!

This method just takes a string, writes the string to a file and then attempt to run the script.
The method writes to the file successfully and prints "printed with success.", but it doesn't execute the file.
I'm not sure if this helps, but this methods is invoked remotely (using RMI) by a servlet.

Please help me!
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the script isn't marked as executable, so it's not going to be runnable. Using RMI might mean you have a SecurityManager installed which blocks this, anyway, but we'll ignore that possibility for a minute; in that case you'd probably see an error message.

Anyway, instead of exec("./testPrinter.sh"), try exec("sh -c ./testPrinter.sh");
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:Well, the script isn't marked as executable, so it's not going to be runnable. Using RMI might mean you have a SecurityManager installed which blocks this, anyway, but we'll ignore that possibility for a minute; in that case you'd probably see an error message.

Anyway, instead of exec("./testPrinter.sh"), try exec("sh -c ./testPrinter.sh");

Howdy Ernest!

I own you a beer!

I don't understand why you said that the script isn't marked as executable. Because I had this in the first line: #!/bin/bash

Other thing that I don't understand is why this code works but the earlier code doesn't:

This method belongs to a class that is in the same package of the code posted earlier. Notice that I only use rt.exec("./testPrinter.sh");

But that's ok. It's working!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!