How I can run python script from QT
-
wrote on 7 Mar 2022, 11:42 last edited by
Re: Run bash script from qt Hi everyone;
How I can run python script from qt Code?Thanks
-
@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
wrote on 7 Mar 2022, 11:45 last edited by@Wasee
As @Christian-Ehrlicher has written, but depending on your version of Linux you may need to specifypython3
to run Python 3 rather than 2.... -
Re: Run bash script from qt Hi everyone;
How I can run python script from qt Code?Thanks
wrote on 7 Mar 2022, 11:58 last edited by@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.
-
wrote on 7 Mar 2022, 12:27 last edited by
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
-
wrote on 7 Mar 2022, 12:44 last edited by
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 need to pass two argument with script to with qt code. These argument entered from the linedit etc.
thankswrote on 7 Mar 2022, 12:52 last edited by@Wasee
Do you really need it detached?
Anyway, arguments can be bundled further down the line:process.startDetached("/bin/python", QStringList({"-c","/home/user/bashScripts/test.py",ui->lineEdit->text().simplified()}));
and so on.
-
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
wrote on 7 Mar 2022, 12:57 last edited by@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
.wrote on 7 Mar 2022, 12:59 last edited by@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.
-
wrote on 7 Mar 2022, 13:08 last edited by
@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.
-
@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.
wrote on 7 Mar 2022, 13:10 last edited by@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.
wrote on 7 Mar 2022, 13:11 last edited by JonB 3 Jul 2022, 13:12@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?
-
wrote on 8 Mar 2022, 04:01 last edited by
@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
-
wrote on 8 Mar 2022, 04:15 last edited by
@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
-
wrote on 8 Mar 2022, 04:50 last edited by
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
1/16