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

How to process in the background without output to the screen

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 613 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.
  • serkan_trS Offline
    serkan_trS Offline
    serkan_tr
    wrote on 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?

    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on 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
        )
        

        If you meet the AI on the road, kill it.

        serkan_trS 1 Reply Last reply
        1
        • serkan_trS serkan_tr has marked this topic as solved on
        • Kent-DorfmanK Kent-Dorfman

          @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_trS Offline
          serkan_trS Offline
          serkan_tr
          wrote on last edited by
          #4

          @Kent-Dorfman
          Thank you

          1 Reply Last reply
          0
          • serkan_trS serkan_tr

            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?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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

            • Login

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