Start script in QProcess?
-
Hi!
I have script:cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.pyHow I can start this script in QProcess?
This not work:m_process.start("cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.py") -
Hi!
I have script:cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.pyHow I can start this script in QProcess?
This not work:m_process.start("cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.py")m_process.start("cmd", [ "/c", "cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.py" ])Or
m_process.setWorkingDirectory("C:/PythonProjects/MibToJson") m_process.start("python", ["C:/PythonProjects/MibToJson/mibToJson.py"]) -
m_process.start("cmd", [ "/c", "cd C:/PythonProjects/MibToJson & python C:/PythonProjects/MibToJson/mibToJson.py" ])Or
m_process.setWorkingDirectory("C:/PythonProjects/MibToJson") m_process.start("python", ["C:/PythonProjects/MibToJson/mibToJson.py"])@JonB If I do this
m_process.execute("cmd", { "/c", "python C:/PythonProjects/MibToJson/mibToJson.py"} );Then I get error:
Python was not foundBut in console cmd this script worked.
And if doing this:m_process.start("python", {"C:/PythonProjects/MibToJson/mibToJson.py"});Then ,y code in script not creadet file.
-
@JonB If I do this
m_process.execute("cmd", { "/c", "python C:/PythonProjects/MibToJson/mibToJson.py"} );Then I get error:
Python was not foundBut in console cmd this script worked.
And if doing this:m_process.start("python", {"C:/PythonProjects/MibToJson/mibToJson.py"});Then ,y code in script not creadet file.
@Mihaill said in Start script in QProcess?:
Python was not found
Then use absolute path to python.exe ...
-
@Mihaill said in Start script in QProcess?:
Python was not found
Then use absolute path to python.exe ...
-
-
-
@jsulm My python script not work and not create file.
It is to cant create filem_process.start("C:/PythonProjectsMibToJson/venv/Scripts/python.exe", { "C:/PythonProjects/MibToJson/mibToJson.py"});@Mihaill
Does yourpython.exeacceptC:/PythonProjects/MibToJson/mibToJson.pyon the command line with those forward slashes? I don't know, if thepython.exeruns but something goes wrong with the path passed in I would make that a native path with backslashes. (The same would also apply in your attempt withcmd /c ...earlier.)Please try to think of others when phrasing your questions or answering.
My python script not work and not create file.
It is to cant create file
What is this about? Create what? You know that we don't know what your script might or might not do, we don't know what "doesn't work" means to you. If you know it tries to create a file from the command line argument why don't you tell us? Otherwise we have no idea what you are talking about.
-
@Mihaill
Does yourpython.exeacceptC:/PythonProjects/MibToJson/mibToJson.pyon the command line with those forward slashes? I don't know, if thepython.exeruns but something goes wrong with the path passed in I would make that a native path with backslashes. (The same would also apply in your attempt withcmd /c ...earlier.)Please try to think of others when phrasing your questions or answering.
My python script not work and not create file.
It is to cant create file
What is this about? Create what? You know that we don't know what your script might or might not do, we don't know what "doesn't work" means to you. If you know it tries to create a file from the command line argument why don't you tell us? Otherwise we have no idea what you are talking about.
-
@JonB I install in OS python, in cmd this work
python C:/PythonProjects/MibToJson/mibToJson.pyMy script mibToJson.py must create file, using absolute path. Script not need arguments.
And it's work in cmd, but not work in QProcess@Mihaill Please add error handling (should be standard in properly written applications):
https://doc.qt.io/qt-6/qprocess.html#errorOccurred
https://doc.qt.io/qt-6/qprocess.html#readAllStandardError -
@Mihaill Please add error handling (should be standard in properly written applications):
https://doc.qt.io/qt-6/qprocess.html#errorOccurred
https://doc.qt.io/qt-6/qprocess.html#readAllStandardError -
@jsulm I get error:
"Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.\r\n"@Mihaill
So you have your answer. Presumably whateverpython.exeyou have somewhere is not on yourPATH.And it's work in cmd, but not work in QProcess
Then are their
PATHs different? Try specifying the full path topythonexecutable asQProcesscommand. -
@jsulm I get error:
"Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.\r\n" -
@Mihaill So, is this patch actually valid: C:/PythonProjectsMibToJson/venv/Scripts/python.exe
What happens if you enter and execute it in cmd.exe? -
M Mihaill has marked this topic as solved on