How run bash script
-
Hi!
I have script :sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/How I can run this script? How I can run this script in QProcess?
@Mihaill
If you want to stick with using<<<you would have to run your command viabash -c "sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/".If you don't want to invoke
bash -cyou would have to invokesudo -Sand then send the string1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/viaQProcess::write()so that it arrives at the sub-process's stdin.To make it work as-is
QProcess p; p.start("/bin/bash", { "-c", "sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/" } );Untested, but the second way might work with
p.start("sudo", { "-S" }); p.write("1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/"); # string might need a terminating `\n`, I don't knowOn a separate note, for my own interest. This whole use of
sudowith a Here-document (the<<<) looks "odd" to me. In principlecommand <<< some textought to be the same as
echo "some text" | commandBut, for unknown/undocumented reason it is not for the
sudo.sudo -S "password echo hello"works, butecho "password echo hello" | sudo -Sgives asudo"usage" error message. That implies to me thatsudobehaves differently depending on whether stdin is or is not attached to a terminal....UPDATE
I misunderstood how<<<works. Turns out, it only reads the next token, not the rest of the line, to present as stdin. Socommand <<< some textactually equates to
echo some | command text. One would needcommand <<< "some text"to equate toecho "some text" | command.As a result of this, my second "untested" proposal above would need to be changed to:
p.start("sudo", { "-S", "./live555ProxyServer", "-v", "rtsp://stream.com:554/Rz.32.02/" }); p.write("1qaz"); # string might need a terminating `\n`, I don't know -
@Mihaill
If you want to stick with using<<<you would have to run your command viabash -c "sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/".If you don't want to invoke
bash -cyou would have to invokesudo -Sand then send the string1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/viaQProcess::write()so that it arrives at the sub-process's stdin.To make it work as-is
QProcess p; p.start("/bin/bash", { "-c", "sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/" } );Untested, but the second way might work with
p.start("sudo", { "-S" }); p.write("1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/"); # string might need a terminating `\n`, I don't knowOn a separate note, for my own interest. This whole use of
sudowith a Here-document (the<<<) looks "odd" to me. In principlecommand <<< some textought to be the same as
echo "some text" | commandBut, for unknown/undocumented reason it is not for the
sudo.sudo -S "password echo hello"works, butecho "password echo hello" | sudo -Sgives asudo"usage" error message. That implies to me thatsudobehaves differently depending on whether stdin is or is not attached to a terminal....UPDATE
I misunderstood how<<<works. Turns out, it only reads the next token, not the rest of the line, to present as stdin. Socommand <<< some textactually equates to
echo some | command text. One would needcommand <<< "some text"to equate toecho "some text" | command.As a result of this, my second "untested" proposal above would need to be changed to:
p.start("sudo", { "-S", "./live555ProxyServer", "-v", "rtsp://stream.com:554/Rz.32.02/" }); p.write("1qaz"); # string might need a terminating `\n`, I don't know@JonB said in How run bash script:
p.start("/bin/bash", { "-c", "sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/" } );
p.start("sudo", { "-S" });
p.write("1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/"); #I try use this, but when I try get output from console -> I get ""
p.readAll() == "";But errorString() == "Unknown error";
How I can get output from console? -
@JonB said in How run bash script:
p.start("/bin/bash", { "-c", "sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/" } );
p.start("sudo", { "-S" });
p.write("1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/"); #I try use this, but when I try get output from console -> I get ""
p.readAll() == "";But errorString() == "Unknown error";
How I can get output from console?@Mihaill
Now you need to look up howQProcessworks. YourreadAll()call is too early, theQProcess::start()has only just started the process.The simplest for your case, if it suffices, is:
p.start("sudo", { "-S" }); p.write("1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/"); # string might need a terminating `\n`, I don't know p.waitForFinished(); qDebug() << p.readAll(); -
@Mihaill
Now you need to look up howQProcessworks. YourreadAll()call is too early, theQProcess::start()has only just started the process.The simplest for your case, if it suffices, is:
p.start("sudo", { "-S" }); p.write("1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/"); # string might need a terminating `\n`, I don't know p.waitForFinished(); qDebug() << p.readAll(); -
@Mihaill
QProcessworks fine.Why don't you try
p.start("ls")orp.start("bash", { "-c", "ls" })to see how that goes?Whether (a) your command line, (b) your
sudo -Sand (c) your./live555ProxyServercommand all behave as desired is a different matter.If you run
sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/on the command line, does it exit (i.e. immediately return to the shell prompt) or stay running (no return to shell prompt)? -
@Mihaill
QProcessworks fine.Why don't you try
p.start("ls")orp.start("bash", { "-c", "ls" })to see how that goes?Whether (a) your command line, (b) your
sudo -Sand (c) your./live555ProxyServercommand all behave as desired is a different matter.If you run
sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/on the command line, does it exit (i.e. immediately return to the shell prompt) or stay running (no return to shell prompt)? -
@Mihaill
QProcessworks fine.Why don't you try
p.start("ls")orp.start("bash", { "-c", "ls" })to see how that goes?Whether (a) your command line, (b) your
sudo -Sand (c) your./live555ProxyServercommand all behave as desired is a different matter.If you run
sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/on the command line, does it exit (i.e. immediately return to the shell prompt) or stay running (no return to shell prompt)?@JonB I used m_proxyServerProcess.waitForFinished();
This code return normal result:m_proxyServerProcess.start("/bin/bash", {"-c","echo 'some text' "}); m_proxyServerProcess.start("ls"); m_proxyServerProcess.start("/bin/bash", { "-c", "ls" });But it's return "" after 5 sec, but process not finished
m_proxyServerProcess.start("/bin/bash", {"-c", "sudo -S <<< 1qaz /home/osm/Downloads/live/proxyServer/live555ProxyServer -v rtsp://stream.lesohranitel.ru:554/RU.32.02/ "}); -
@JonB I used m_proxyServerProcess.waitForFinished();
This code return normal result:m_proxyServerProcess.start("/bin/bash", {"-c","echo 'some text' "}); m_proxyServerProcess.start("ls"); m_proxyServerProcess.start("/bin/bash", { "-c", "ls" });But it's return "" after 5 sec, but process not finished
m_proxyServerProcess.start("/bin/bash", {"-c", "sudo -S <<< 1qaz /home/osm/Downloads/live/proxyServer/live555ProxyServer -v rtsp://stream.lesohranitel.ru:554/RU.32.02/ "});@Mihaill
If you want help answer questions asked. It's really not too hard. I last wrote:If you run
sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/on the command line, does it exit (i.e. immediately return to the shell prompt) or stay running (no return to shell prompt)?I asked that question because it is 100% vital to your question/behaviour/code. You know how your
live555ProxyServercommand behaves, how can I possibly know? Your ignoring it does not help either of us. -
@Mihaill
If you want help answer questions asked. It's really not too hard. I last wrote:If you run
sudo -S <<< 1qaz ./live555ProxyServer -v rtsp://stream.com:554/Rz.32.02/on the command line, does it exit (i.e. immediately return to the shell prompt) or stay running (no return to shell prompt)?I asked that question because it is 100% vital to your question/behaviour/code. You know how your
live555ProxyServercommand behaves, how can I possibly know? Your ignoring it does not help either of us. -
M Mihaill has marked this topic as solved on
-
@JonB In command line it's running.
I check this code and code works, but readAll() == "". It's strange.
Thanks for help.@Mihaill said in How run bash script:
@JonB In command line it's running.
I don't known what that means.
Do you mean that after typing
sudo -S <<< 1qaz /home/osm/Downloads/live/proxyServer/live555ProxyServer -v rtsp://stream.lesohranitel.ru:554/RU.32.02/in a terminal the command prompt does not appear again andlive555ProxyServerkeeps running? I would like to help you but it's so difficult to get the answers out from you! :)