echo redirect with QProcess
-
Hi
I want to use QProcess() with "echo".
In terminal, $ echo "some out put" > test.txt , is OK.
But, QProcess start("echo "some out put" > test.txt"), does not work.
Finally, I want to call usb unbind/bind from Qt app.
I want to run "echo "usb1" > /sys/bus/usb/drivers/unbind".
Are there any solutions ?
Best Regards,
-
-
Hi
I want to use QProcess() with "echo".
In terminal, $ echo "some out put" > test.txt , is OK.
But, QProcess start("echo "some out put" > test.txt"), does not work.
Finally, I want to call usb unbind/bind from Qt app.
I want to run "echo "usb1" > /sys/bus/usb/drivers/unbind".
Are there any solutions ?
Best Regards,
@Shin.go
In your commands, it is the>output redirection symbol which is your problem. Only a shell (e.g./bin/shor/bin/bash) understands that symbol and what to do about it. You have two choices:-
Handle the redirection to file yourself prior to calling
QProcessor similar. Nicest, but most work.
(EDIT: I see there isQProcess::setStandardOutputFile(const QString &fileName, OpenMode mode = Truncate). You could use this and remove your> text.txtfrom your command line, then your command should work without needing a shell to interpret the>. Note that it will use/bin/echo(or whatever is on yourPATH) rather than a shell's built-inecho. -
Make the whole of your command line into a single string to be handled by the shell, and do a
QProcessof the shell with that as an argument. Untested by me, but something like:
/bin/sh -c 'echo "some out put" > test.txt'
-