Sourcing a script using QProcess
-
Try with
p.start("bash", QStringList() << "-c" << "\"\"source /path/to/test.sh\"\"");
-
wrote on 14 Jan 2016, 13:27 last edited by
@SGaist
The process runs and the exit code is 0, but the script is not executed. By the way if I try to execute the following on prompt:/bin/sh -c ""source /path/to/test.sh""
it does "nothing" (I mean no errors nor echo output).
-
How are you checking that it does nothing with QProcess ?
In the console version you have too much quotes it should only be
bash -c "source /path/to/test.sh"
-
How are you checking that it does nothing with QProcess ?
In the console version you have too much quotes it should only be
bash -c "source /path/to/test.sh"
wrote on 14 Jan 2016, 14:29 last edited byHow are you checking that it does nothing with QProcess ?
The env vars are not exported and there is no echo.
In the console version you have too much quotes it should only be bash -c "source /path/to/test.sh"
Yes, in this way the echo is shown but the vars are not exported. It's the same as run the script directly without sourcing it. But it's beyond my knowledge to understand why.
-
Can I ask silly question?
If you run bash first, wont the export be in that instance of bash?
source test.sh;echo $MYVAR
does as expected
but not with bash first. -
On OS X putting the echo call inside the "command string" worked.
I'm reading stdout using readAllStandardOutput
-
On OS X putting the echo call inside the "command string" worked.
I'm reading stdout using readAllStandardOutput
-
You can set the environment using
QProcess::setProcessEnvironment(const QProcessEnvironment & environment)
You can get the environment of your current process via
QProcessEnvironment::systemEnvironment()
-
@Mark81 Yes both the Hello World and content of the variable were shown. Again it's on OS X with a recent version of bash.
15/15