Fs.exec() time out problem

Hi everyone,
I migrate my old luci app from lua to current js app, I need execute some lengthy commands in shell script from web page, it will cause xhr request time out, so I add '&' at the end of command to throw it to background, it's ok with old lua because it use io.popen() to run shell command. But current app use fs.exec() to run shell command, my lengthy command will cause fs.exec() timeout with or without '&", in fact, if you add a '&' at any command line of a shell script, fs.exec() will time out, even a script include just one command line of "echo hello &" , and you use fs.exec() to run this script , it will cause xhr time out. How can I use '&' in a script and run this script with fs.exec() or other shell command call in new luci app ?

Have you tried having the script you call itself fork another script, then exit and return? Don't put the & in the luci app, put it in the script.

I tried, same result.
If you put '&' in args of fs.exec(), just like fs.exec('echo',['hello','&']) , '&' will interpreted as text.
If you put echo hello & in /home/1.sh and run fs.exec('/home/1.sh',null), xhr request time out error.
if you put echo hello & in /home/2.sh and put /home/2.sh in /home/1.sh, and run fs.exec('/home/1.sh',null), xhr request time out error.

Try using disown in the script to disassociate it from the job control. That might detach it.

fs.exec('/root/test.sh',null)

test.sh:

#!/bin/sh
(
  echo -n Do... >> /root/test.out
  sleep 10
  echo -n whatever... >> /root/test.out
  sleep 10
  echo -n you... >> /root/test.out
  sleep 10
  echo want! >> /root/test.out
  sleep 10
) & disown
exit 0

disown not found with busybox ash of openwrt.

Yes, you'll have to use bash for that. Try it with bash. If it works, can probably then come up with a more universal solution.

no, I prefer solution that make fs.exec() behave like io.popen().
If must install bash to solve this issue, I'd rather install luci-lua-runtime to use my old lua code , because it's simple and small .

I understand, but if you will test with bash and disown, if that works, I think we can get it to also work without bash. Just to test.

Very strange result.
with this shcript test.sh:

#!/bin/bash
echo hello & disown

and this luci app code:


    handleCommand: function(exec, args) {
		return fs.exec(exec, args).then(function(res) {
			var out = document.querySelector('textarea');

			dom.content(out, [ res.stdout || '', res.stderr || '' ]);
		}).catch(function(err) {
			ui.addNotification(null, E('p', [ err ]))
		})
	},
    myhandle: function(ev, cmd) {
			return this.handleCommand('/root/test.sh',null);
	},

after some times normally return , it will fall into xhr request time out error again, usually 3 to 4 times of normal , seems random.

Have you considered running a shell script from RPC daemon and returning results to the js via promise?

I don't know how to learn to run shell scripts from rpc daemon and get result via promise.
I just want to normally return when use '&' just like shell ,not xhr time out.