How to process in the background without output to the screen
-
wrote on 25 Jan 2023, 10:25 last edited by
I want to write a program. The purpose of the program is to open cmd and run ROS, enter the command "c:\opt\ros\foxy\x64\setup.bat" in cmd and run the Qt project I wrote in another file. I do not want these processes to appear on the screen.
Necessary information: ROS is a framework that provides an operating system for robot software developers. For ROS to work ,c:\opt\ros\foxy\x64\setup.bat
must be run in a cmd and processes must be resumed in that cmd.
I also made a Qt project, but my project doesn't work when I tap .exe directly. It works when I first run ROS via cmd and then run .exe via the same cmd.
It's kind of annoying to do this all the time, so I want to write a Qt project that does these steps for me. and I don't want these settings to appear on the screen in the background
Can something like this be done or is there an easier way? -
Hi,
Sounds like you would need some kind of launcher using QProcess to start your ros environment and then your application.
Can you do the launch from a script ?
-
wrote on 25 Jan 2023, 19:58 last edited by
@serkan_tr said in How to process in the background without output to the screen:
Can something like this be done or is there an easier way?
Well, if you were in a non-windoze environment you would execute a script containing
#! /bin/bash ( . $PATH_TO_SETUP/setup.sh $PATH_TO_EXE/qtprogram 2>&1 > /dev/null )
-
-
@serkan_tr said in How to process in the background without output to the screen:
Can something like this be done or is there an easier way?
Well, if you were in a non-windoze environment you would execute a script containing
#! /bin/bash ( . $PATH_TO_SETUP/setup.sh $PATH_TO_EXE/qtprogram 2>&1 > /dev/null )
wrote on 22 Feb 2023, 05:04 last edited by@Kent-Dorfman
Thank you -
I want to write a program. The purpose of the program is to open cmd and run ROS, enter the command "c:\opt\ros\foxy\x64\setup.bat" in cmd and run the Qt project I wrote in another file. I do not want these processes to appear on the screen.
Necessary information: ROS is a framework that provides an operating system for robot software developers. For ROS to work ,c:\opt\ros\foxy\x64\setup.bat
must be run in a cmd and processes must be resumed in that cmd.
I also made a Qt project, but my project doesn't work when I tap .exe directly. It works when I first run ROS via cmd and then run .exe via the same cmd.
It's kind of annoying to do this all the time, so I want to write a Qt project that does these steps for me. and I don't want these settings to appear on the screen in the background
Can something like this be done or is there an easier way?wrote on 22 Feb 2023, 08:57 last edited by JonB@serkan_tr
From Windows you can do the equivalent of @Kent-Dorfman's Linux shell script in a.bat
file which you run fromQProcess
.However there is a "wrinkle". @Kent-Dorfman's code allows for
setup.sh
setting environment variables for the followingqtprogram
call because in. $PATH_TO_SETUP/setup.sh
that.
at the start causes thesetup.sh
to be run in the same shell instance as theqtprogram
which follows it.If you Windows
.bat
file just goes:c:\opt\ros\foxy\x64\setup.bat qtprogram
then any environment variables set in
setup.bat
will not be inherited toqtprogram
. And fromFor ROS to work ,
c:\opt\ros\foxy\x64\setup.bat
must be run in a cmd and processes must be resumed in that cmd.I am guessing it may well set such variables.
I believe
call
is the vital word to achieve what you need from a.bat
file. It must be used when that executes any other.bat
file which sets environment variables [actually I think this is necessary any time you want to call one.bat
file from another and expect it to return into the first.bat
file to continue]:call c:\opt\ros\foxy\x64\setup.bat qtprogram
If this is put in some
setupandrun.bat
file you execute that viaQProcess::start()
(orstartDetached()
) I am not sure for a.bat
file whether you can run it directly viastart("/path/to/bat")
, you might have to gostart("cmd", { "/c", "/path/to/bat" })
.Finally: I just did a test to see if you can avoid the need for the extra
setupandrun.bat
file you would have to write/distribute. I believe you can do that by:process->start("cmd", { "/c", R"(c:\opt\ros\foxy\x64\setup.bat & \path\to\qtprogram)" });
1/5