Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Command Runner (azexec) for Ubuntu (and others Linux)
#1
Hi,
Recently passed from Windows to Ubuntu 16.04, and I'm not able to correctly use "Command Runner" plugin anymore.
After lots of searches, it seems to me that the plugin is not Linux & Mac compliant due to the way of working of "Runtime exec" java class/method in Unix systems.
The source file of azexec (last version 1.3.2) has a function "public void onCompletion(Download d)" which run the command this way :

Code:
final String command_to_run = command;
plugin_interface.getUtilities().createThread(d.getName() + " exec", new Runnable() {
public void run() {
channel.log("Executing: " + command_to_run);
boolean use_runtime_exec = use_runtime_exec_param.getValue();
try {
if (use_runtime_exec) {
Runtime.getRuntime().exec(command_to_run);
}
else {
plugin_interface.getUtilities().createProcess(command_to_run);
}
}
catch (Throwable t) {
channel.logAlert("Unable to run \"" + command_to_run + "\".", t);
}
}
});
the plugin log contains the good full command thanks to this :

Code:
channel.log("Executing: " + command_to_run);
and no error return through this :

Code:
catch (Throwable t) {
channel.logAlert("Unable to run \"" + command_to_run + "\".", t)
But for both shell command run functions :

Code:
plugin_interface.getUtilities().createProcess(command_to_run);
and

Code:
Runtime.getRuntime().exec(command_to_run);
it's not working as expected.
I don't know why for the first implementation (don't know how it's executed after) but for the second way, I'm quite sure it can't work in unix as soon as there are special caracters in (and there's generally quotes in %D or other torrent path/name/... or double quotes needed by user) because of unix/java way of interpreting command with exec()...
To reproduce the issue, just try to run something like that in command run, on UNIX :

Code:
ls -ltr > "/tmp/result.log"

Someone more advanced than me in java could probably easyly fix this issue in plugin and update azexec plugin ?
Thanks a lot for your answers & advices.

Regards,
Rudy
Reply
#2
Had a look at native implementation :

Code:
plugin_interface.getUtilities().createProcess(command_to_run);
and I did not understood because it's seems that this method is not implemented for UNIX platform as it is for MAC & WIN32... ?!
in : http://svn.vuze.com/public/client/tags/R...rImpl.java
we can read :

Code:
public void createProcess(String command_line, boolean inherit_handles)
throws PlatformManagerException {
throw new PlatformManagerException(ERR_UNSUPPORTED);
}
Well, in 3 words : I'm lost :(

Help would be great.
Reply
#3
Create a shell script and call that, passing arguments as required. For example

/tmp/cmd.sh %D

The script can then access %D via $1

Make sure it is executable!
Reply
#4
(08-22-2016, 02:12 PM)'parg' Wrote: Create a shell script and call that, passing arguments as required. For example

/tmp/cmd.sh %D

The script can then access %D via $1

Make sure it is executable!



 
Thanks for the reply and advice. That's what I finally (as a workaround) did but not the way you're telling because it's not enough.
Assume the %D = /my drive/movies
The values you get in your shell are :
$1 = /my
$2 = drive/movies
Because java seems to use "StringTokenizer", splitting on spaces !
Even if you put quotes, that's not changing anything unfortunatly...

Well, to be honnest, I found a workaround using special characters to split my vars : %D, %F, ... PS about another bug : %K (single or multi file torrent) is missing in the availables vars on the window even if it exists.
The way I did the job (for exemple) in shell is :
- send from vuze : myScrit.sh %D###%FFF
- in shell : replace all spaces in args ($*)  with another special chars like £££
- split my args on ###
- put back my spaces, replacing £££

Obiously, I don't think it's easy to do (and resilient)... You should try to ease this for all users on Vuze side, if possible...
Don't you think ?

Thanks for your time
Reply
#5
OK, I confirm that the method
Code:
final String command_to_run = command;
[...snip...]
Runtime.getRuntime().exec(command_to_run);
can't work as expected.
Because the String is passed by java in StringTokenizer, splitting everything with spaces, whatever you try to do !

The way it should be implemented in Vuze azexec plugin (and probably also in Vuze plugin interface) is through the "exec(String[])  <= Array of Strings" method, with a way, provided to the user, to specify multiples "values" (something like "add a new argument" in a new textbox).
The first text box must be the "shell command to execute", the 1st (optionnal) added textbox the 1st arg, the 2nd textbox for the 2nd arg and so on (up to the user to add 1st arg or more).

Next, you look at each textbox in same order to construct the String[] and throw it in exec command...

Am I wrong ?
Reply
#6
No, you're right, but it isn't my plugin - perhaps you could take over maintenance of it and send me fixes?

There's actually more complexity to correctly invoking external programs than even that, we found that to cover all eventualities (non-ascii characters for example) we had to use environment variables and use the ProcessBuilder - see 'createProcessBuilder' in

https://svn.vuze.com/public/client/trunk...Utils.java

There's also the JavaScript plugin (http://wiki.vuze.com/w/JavaScript) where it is possible to do things like set up an 'execute on assign' action for the 'completed' tag, but that is reasonable complex to do.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
Bug Vuze 5.7.10 crashes on Linux Ubuntu 14.04 LTS highlander 3 8,513 01-12-2018, 09:56 PM
Last Post: highlander
  Torrents will not stop on command bug neinome 2 5,315 10-22-2017, 06:25 AM
Last Post: Havokdan



Users browsing this thread: 1 Guest(s)