Can I execute a Linux binary from a Windows application?
If you want to go with WSL, you can just run wsl myLinuxProgram --options
.
Using WSL is the easiest way I believe as the current directory (PWD), is the current one i.e. the same as the PWD of your Qt app.
You can read Microsoft documenation for more info: https://docs.microsoft.com/en-us/windows/wsl/interop
If your linux binary depends on a lots of things, I really suggest you use docker for windows. Then, you have chance to pre-build an own docker image which put all dependency software also the linux binary you need to run in it.
Of course, to let your customer to use it, you should put it to dockerhub, register an account for yourself.
Then, the solution is simple: let the QT application to call docker run
to setup a container base on your own image, execute it, and also let the linux binary to write the log or others to the bind mount volume among linux container & windows. After it run, the QT application fetch the linux binary output from this shared folder.
Finally, I give a minimal workable example for your reference:
Suppose the shared folder between windows & linux container is:
C:\\abc\\log_share
, it will mapped to linux container as/tmp
folder. Of course you need to allow volume share by right click thedocker icon
in windows tray area & choose settings, like described hereSimplify the windows application as
bat file
, and simplfy the docker image asubuntu
, you should use your own prebuilt docker image with all dependency in it:win_app.bat:
ECHO OFF ::New a shared folder with linux container RD /s/q C:\\abc\\log_share > NUL 2>&1 MKDIR C:\\abc\\log_share ::From windows call docker to execute linux command like 'echo' echo "Start to run linux binary in docker container..." docker run -it -v C:\\abc\\log_share:/tmp ubuntu:16.04 bash -c "echo 'helloworld' > /tmp/linux_log_here.txt" ::In windows, get the log from shared bind mount from linux echo "Linux binary run finish, print the log generated by the container..." type C:\\abc\\log_share\linux_log_here.txt
Simplify the linux binary just as
echo command
in linux, the output things should be all write to shared directory:echo 'helloworld' > /tmp/linux_log_here.txt
Now, execute the bat file with command win_app.bat
:
C:\abc>win_app.bat
C:\abc>ECHO OFF
"Start to run linux binary in docker container..."
"Linux binary run finish, print the log generated by the container..."
helloworld
You can see the windows application already could fetch things(here is helloworld
) which generated by linux binary from docker container.