How I can run python script from QT
-
@Wasee said in How I can run python script from QT:
How I can run python script from qt Code?
Instead executing
/bin/bash
execute/bin/python
maybe? -
Re: Run bash script from qt Hi everyone;
How I can run python script from qt Code?Thanks
-
Re: Run bash script from qt Hi everyone;
How I can run python script from qt Code?Thanks
@Wasee To add a bit: if your script is configured (chmod +x and shebang) to run independently you can also use the same methodology as for running the bash script (bash will call interpreter defined in the shebang) - sometimes you might need shell environment for your script. It all depends on what the script does.
-
Hi everyone;
I need to pass two argument with script to with qt code. These argument entered from the linedit etc.
thanks -
Hi everyone;
I coded following but did not run script;QProcess process; process.startDetached("/bin/python", QStringList() << "-c" << "/home/user/bashScripts/test.py"); qDebug()<<"Welcome";
thanks
@Wasee said in How I can run python script from QT:
process.startDetached("/bin/python", QStringList() << "-c" << "/home/user/bashScripts/test.py");
As I stated earlier, is
/bin/python
correct for your desired Python on your machine?Since when has Python used a
-c
argument to run a script? Did you try/bin/python -c /home/user/bashScripts/test.py
from the command-line first? Remove that-c
argument?If it still does not work, check for errors and any output to stdout/stderr from
QProcess
. -
@Wasee said in How I can run python script from QT:
process.startDetached("/bin/python", QStringList() << "-c" << "/home/user/bashScripts/test.py");
As I stated earlier, is
/bin/python
correct for your desired Python on your machine?Since when has Python used a
-c
argument to run a script? Did you try/bin/python -c /home/user/bashScripts/test.py
from the command-line first? Remove that-c
argument?If it still does not work, check for errors and any output to stdout/stderr from
QProcess
.@JonB said in How I can run python script from QT:
Since when has Python used a -c argument to run a script?
https://docs.python.org/3/using/cmdline.html
seems legit? I assumed the OP knows how to call an interpreter and used the parameter deliberately.
-
@JonB said in How I can run python script from QT:
Since when has Python used a -c argument to run a script?
https://docs.python.org/3/using/cmdline.html
seems legit? I assumed the OP knows how to call an interpreter and used the parameter deliberately.
@artwaw
Nope, you mis-read what is there!python [-c command]
runs
command
as as python, not as a python file of script.As it says there, to run a script file it's
python myscript.py
I imagine the OP copied the
-c
directly from the example of the Bash script, which does use-c
for a file:/bin/bash -c myscript.sh
:)
-
@artwaw said in How I can run python script from QT:
process.startDetached("/bin/python", QStringList({"-c","/home/user/bashScripts/test.py",ui->lineEdit->text().simplified()}));
Didn't run script by changing the code.
@Wasee said in How I can run python script from QT:
process.startDetached("/bin/python", QStringList({"-c","/home/user/bashScripts/test.py",ui->lineEdit->text().simplified()}));
Didn't run script by changing the code.Already told you why earlier, what you should test, and what you need to have. Any particular reason to just ignore me?
-
@JonB Hi;
I run in command-line following commands: command not found
user@user-HP:~$ sudo /bin/python -c /home/user/bashScripts/test.py
[sudo] password for user:
sudo: /bin/python: command not found
user@user-HP:~$ sudo /bin/python /home/user/bashScripts/test.py
[sudo] password for user:
sudo: /bin/python: command not found
user@user-HP:~$thanks
-
@JonB said in How I can run python script from QT:
python myscript.py
Its work perfect now I want to pass two arguments with my script from UI basically two different integers.
thanks
-
Hi everyone;
I coded following my script run successfully:process.startDetached("python /home/user/bashScripts/test.py");
But when I pass arguments then my script fails to run ; I coded following script as argument:
process.startDetached(({"python /home/user/bashScripts/test.py",(ui->pan->text().simplified()),(ui->tilt->text().simplified());}));
thanks
-
Hi everyone;
I coded following my script run successfully:process.startDetached("python /home/user/bashScripts/test.py");
But when I pass arguments then my script fails to run ; I coded following script as argument:
process.startDetached(({"python /home/user/bashScripts/test.py",(ui->pan->text().simplified()),(ui->tilt->text().simplified());}));
thanks