Unsolved How do I run docker using QProcess?
-
You should take a look at QProcess::setArguments(): http://doc.qt.io/qt-5/qprocess.html#setArguments
-
Arguments <<"/k" <<"docker exec -ti freesurfer bash"; -> is Okay,
but
Arguments <<"/k" <<"docker exec -ti freesurfer bash << "ls";
I want the user to be able to interact with the command prompt window and send their own commands is it possible??
-
-
@Pablo-J.-Rogina
I don't really get when those authors expect that to work. They clone the calling process'stdin
to pass on to the child (instead of usual redirection). But assuming your Qt app is GUI, and say launched from a desktop shortcut, it won't start with any (open)stdin
to clone, will it? -
Arguments <<"/k" <<"docker exec -ti freesurfer ls -la /opt/freesurfer";
I conformed, above arguments doing well. that means, above arguments run a docker.
"docker exec -ti freesurfer ls -la /opt/freesurfer"; -> this arguments is composed of 3 windows? command line
(docker exec -ti freesurfer) + (opt/freesurfer) + (ls). -
@Pablo-J.-Rogina
Pablo-J.-RoginaI learned Qt 3 days....
Arguments <<"/k" <<"docker exec -ti freesurfer" <<"export " <<"source " <<"export " <<"convert";
CommandPrompt.startDetached("cmd", Arguments);Do you think is it possible syntax?? to send multiple arguments.
-
Hi
I used the following code to run python interactively.
(code from https://stackoverflow.com/questions/48518442/qt-start-process-in-interactive-shell )#include <QProcess> #include <QString> #include <QStringList> #include "Windows.h" class QDetachableProcess : public QProcess { public: QDetachableProcess(QObject *parent = 0) : QProcess(parent) { } void detach() { waitForStarted(); setProcessState(QProcess::NotRunning); } }; int main(int argc, char *argv[]) { QDetachableProcess process; QString program = "cmd.exe"; QStringList arguments = QStringList() << "/K" << "python.exe"; process.setCreateProcessArgumentsModifier( [](QProcess::CreateProcessArguments *args) { args->flags |= CREATE_NEW_CONSOLE; args->startupInfo->dwFlags &=~ STARTF_USESTDHANDLES; }); process.start(program, arguments); process.detach(); return 0; }
However, im not sure how docker works as it seems it starts a linux bash inside ?
So im wondering which of the shells/command promts you want to be interactive.
The windows one, or the linux one. ( if it works thats way) -
@KKyul
Please just tell us exactly what you would type in a terminal to run the command. For example, is it perhaps:docker exec -ti freesurfer ls -la /opt/freesurfer
or does it have quotes or what?
You keep writing:
Arguments <<"/k" ...
what is that/k
about, and what program is thisArguments
for?I want to execute multiple window cmd command using a QProcess? or other function
What is "multiple window" all about? It means nothing to me.
-
@mrjj said in How do I run docker using QProcess?:
The windows one, or the linux one. ( if it works thats way)
exactly... I want to interactive with linux shells command.
following code
Arguments <<"/k" <<"docker exec -ti freesurfer" <<"export FREESURFER_HOME=/opt/freesurfer" <<"source $FREESURFER_HOME/SetUpFreeSurfer.sh" <<"export SUBJECTS_DIR=/opt/freesurfer" <<"mri_convert sample-001.mgz sample-001.nii.gz";
I want above codes are processed at once.
-
@JonB said in How do I run docker using QProcess?:
I want to execute multiple window cmd command using a QProcess? or other function
I honestly do not know about / k It's code from the Internet....
I want to interactive with linux shell command.
- "docker exec -ti freesurfer"
2)"export FREESURFER_HOME=/opt/freesurfer"
3)"source $FREESURFER_HOME/SetUpFreeSurfer.sh"
4)"export SUBJECTS_DIR=/opt/freesurfer"
5)"mri_convert sample-001.mgz sample-001.nii.gz";
I want to execute above those command at once!
- "docker exec -ti freesurfer"
-
Hmm but the
export statements are really not parameters. its bash stuff.
Would it be an option to put in all in convert.sh file and
simply run that ? -
@mrjj
okay! I will do make a .sh file!! thanks alot !! -
@KKyul
I think it will work faster as im not sure if the
bash inside docker will see the export correctly with QProcess.
However, inside .sh file, it will just work as it should be in context of the bash if i read the docs right.
I really ought to try Docker on windows. Pretty cool tech. -
I honestly do not know about / k It's code from the Internet....
OK. I'm going to guess what I think you're looking at and want.
You are under Windows (your Qt app, where you want to run Docker out of). The Windows shell,
cmd.exe
. That accepts a/k
argument to remain around (as a console) after executing a command line. The command line treats the rest of the line as the command to execute first. @mrjj's code you show explicitly creates a new console in a window for the sub-process.So your code would be:
QStringList arguments = QStringList() << "/K" << "docker exec -ti freesurfer";
You are putting the
export
etc. statements in aconvert.sh
file (they cannot be put on the command-line). This needs executing by thedocker
. You have to tell it to execute that. So doesdocker
accept a command-line e.g.docker exec -ti freesurfer convert.sh
or rather, quite probably:
docker exec -ti freesurfer "/bin/bash convert.sh"
-
Hi,
As an additional test, since you have an interactive session, why not use
QProcess::write
with the lines you would like to execute ?