Context : I'm developing tests for a java program.
I have a shell script that links java code and interpret it.
In another folder, I wanted to execute this script with the Command struct, and with the currrent_dir function.
When I try my code, the shell script seems to work well, however at a moment of the execution, the execution is automatically put to the background but I don't know why.
I don't want the execution to be put to the background, would someone know how to stop this automatic behaviour ?
Here the part of my code causing the background mode activated for the Command execution :
let output = Command::new("/usr/bin/bash")
.current_dir("/home/admin/Desktop/work/dev")
.args(["-ic", ProgExeAlias])
.output()
.expect("ERROR on executing the bash alias for\
executing the program.");
It seems to be related to the bash interractive mode (the -i option).
By "background mode", do you mean that it doesn't show stdout or allow you to input test on stdin?
I think it becomes more complicated to both collect output and display it, using spawn() (instead of output()) and manually reading from the stdio handle.
So as the above image testifies :
I did a fg 2 and I had the second test begin run. fg 2 again and this time the third and last test was being run. fg 2 again, and then I got the final result.
I noticed that I could wait as long as I wanted between each fg command, it's like if the processus had been on pause once it had been "Stopped" and that by doing the foreground command I resumed it.
So the main problem with all that is that I have to each time "resume" the following test by doing a fg.
However I found a solution to the problem : rather than calling an alias (ProgExeAlias) which execute a shell script, I've created a new shell script that does what the alias does, and now I merely directly call this shell script, and that works.
Nonetheless, I don't think that the solution I found is the "real" one to the original problem.
When you call .status(), you're setting up the command to be executed with no stdin. But bash's -i required stdin to prompt the user.
You can either remove -i or use .stdin(Stdio::piped()) and write to the pipe (refer to the second example of Stdio in std::process - Rust for details).