You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried the lib but while executing line commands everything is working fine when I try to execute scripts I found that the script never executes.
I was able to find that the problem is in the exit. Whenever I use exit (also in commands) the lib always returns code -1. I tried to substitute the exit by return but I always get the code -1.
I tried a sync call:
Shell.Result result = Shell.su(getResources().openRawResource(resId)).exec();
mTvCode.setText("Code: " + result.getCode());
List out = result.getOut();
StringBuilder sbOut = new StringBuilder();
if (out != null) {
for (String o : out) {
sbOut.append(o);
}
}
mTvOutput.setText("Out: " + sbOut.toString());
List err = result.getErr();
StringBuilder sbErr = new StringBuilder();
if (err != null) {
for (String e : err) {
sbErr.append(e);
}
}
mTvErr.setText("Err: " + sbErr.toString());
And I tried async call:
Shell.su(getResources().openRawResource(R.raw.script))
.to(consoleList)
.submit(result -> {
mTvCode.setText("Code: " + result.getCode());
List out = result.getOut();
StringBuilder sbOut = new StringBuilder();
if (out != null) {
for (String o : out) {
sbOut.append(o);
}
}
mTvOutput.setText("Out: " + sbOut.toString());
List err = result.getErr();
StringBuilder sbErr = new StringBuilder();
if (err != null) {
for (String e : err) {
sbErr.append(e);
}
}
mTvErr.setText("Err: " + sbErr.toString());
});
The result is always the same.
Here's one script example:
#!/system/bin/sh
function exit_error(){
case "$1" in
1)
echo 'busybox is not installed'
;;
esac
#exit 2
return 2
}
busybox > /dev/null || exit_error 1
if [[ ! -f /sdcard/file.txt ]]; then
echo 'File not exists'
#exit 1
return 1
fi
echo 'Exiting'
#exit 0
return 0`
Am I doing something wrong or is this a limitation?
Thanks in advance.
JS
The text was updated successfully, but these errors were encountered:
You should never terminate the shell! The shell in libsu is a long living session, exiting will terminate the process, and thus it cannot retrieve the return code.
You can run that code in a subshell, e.g. (shell_script) or sh shell_script, which will fork another process from the shell, and exiting will only terminate the subshell but not the shell used in libsu
Hi @topjohnwu.
Great job and thanks for your work!
I tried the lib but while executing line commands everything is working fine when I try to execute scripts I found that the script never executes.
I was able to find that the problem is in the exit. Whenever I use exit (also in commands) the lib always returns code -1. I tried to substitute the exit by return but I always get the code -1.
I tried a sync call:
And I tried async call:
The result is always the same.
Here's one script example:
Am I doing something wrong or is this a limitation?
Thanks in advance.
JS
The text was updated successfully, but these errors were encountered: