How run bash script
-
wrote on 19 Apr 2023, 10:47 last edited by
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?
-
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?
wrote on 19 Apr 2023, 11:13 last edited by JonB@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 -c
you would have to invokesudo -S
and 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 know
On a separate note, for my own interest. This whole use of
sudo
with a Here-document (the<<<
) looks "odd" to me. In principlecommand <<< some text
ought to be the same as
echo "some text" | command
But, for unknown/undocumented reason it is not for the
sudo
.sudo -S "password echo hello"
works, butecho "password echo hello" | sudo -S
gives asudo
"usage" error message. That implies to me thatsudo
behaves 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 text
actually 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 -c
you would have to invokesudo -S
and 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 know
On a separate note, for my own interest. This whole use of
sudo
with a Here-document (the<<<
) looks "odd" to me. In principlecommand <<< some text
ought to be the same as
echo "some text" | command
But, for unknown/undocumented reason it is not for the
sudo
.sudo -S "password echo hello"
works, butecho "password echo hello" | sudo -S
gives asudo
"usage" error message. That implies to me thatsudo
behaves 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 text
actually 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
wrote on 19 Apr 2023, 11:39 last edited by Mihaill@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?wrote on 19 Apr 2023, 11:41 last edited by@Mihaill
Now you need to look up howQProcess
works. 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 howQProcess
works. 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();
-
wrote on 19 Apr 2023, 12:01 last edited by JonB
@Mihaill
QProcess
works 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 -S
and (c) your./live555ProxyServer
command 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
QProcess
works 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 -S
and (c) your./live555ProxyServer
command 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)?wrote on 19 Apr 2023, 12:12 last edited byThis post is deleted! -
@Mihaill
QProcess
works 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 -S
and (c) your./live555ProxyServer
command 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)?wrote on 19 Apr 2023, 12:26 last edited by Mihaill@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/ "});
wrote on 19 Apr 2023, 12:30 last edited by JonB@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
live555ProxyServer
command 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
live555ProxyServer
command behaves, how can I possibly know? Your ignoring it does not help either of us. -
-
@JonB In command line it's running.
I check this code and code works, but readAll() == "". It's strange.
Thanks for help.wrote on 19 Apr 2023, 13:39 last edited by@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 andlive555ProxyServer
keeps running? I would like to help you but it's so difficult to get the answers out from you! :)
1/11