Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to process in the background without output to the screen
Forum Updated to NodeBB v4.3 + New Features

How to process in the background without output to the screen

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 540 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    serkan_tr
    wrote on 25 Jan 2023, 10:25 last edited by
    #1

    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?

    J 1 Reply Last reply 22 Feb 2023, 08:57
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Jan 2023, 19:25 last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kent-Dorfman
        wrote on 25 Jan 2023, 19:58 last edited by
        #3

        @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
        )
        

        I light my way forward with the fires of all the bridges I've burned behind me.

        S 1 Reply Last reply 22 Feb 2023, 05:04
        1
        • S serkan_tr has marked this topic as solved on 13 Feb 2023, 12:49
        • K Kent-Dorfman
          25 Jan 2023, 19:58

          @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
          )
          
          S Offline
          S Offline
          serkan_tr
          wrote on 22 Feb 2023, 05:04 last edited by
          #4

          @Kent-Dorfman
          Thank you

          1 Reply Last reply
          0
          • S serkan_tr
            25 Jan 2023, 10:25

            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?

            J Offline
            J Offline
            JonB
            wrote on 22 Feb 2023, 08:57 last edited by JonB
            #5

            @serkan_tr
            From Windows you can do the equivalent of @Kent-Dorfman's Linux shell script in a .bat file which you run from QProcess.

            However there is a "wrinkle". @Kent-Dorfman's code allows for setup.sh setting environment variables for the following qtprogram call because in . $PATH_TO_SETUP/setup.sh that . at the start causes the setup.sh to be run in the same shell instance as the qtprogram 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 to qtprogram. And from

            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 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 via QProcess::start() (or startDetached()) I am not sure for a .bat file whether you can run it directly via start("/path/to/bat"), you might have to go start("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 Reply Last reply
            1

            1/5

            25 Jan 2023, 10:25

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved