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. When running cmd.exe from window 7.x to QProcess.. Not work path environment...
Forum Updated to NodeBB v4.3 + New Features

When running cmd.exe from window 7.x to QProcess.. Not work path environment...

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 3.1k Views 2 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.
  • DaryongD Offline
    DaryongD Offline
    Daryong
    wrote on last edited by Daryong
    #1

    Hello.
    Look at the simple source below. please..

    < source >
    QProcess process;

    process.setProcessChannelMode(QProcess::MergedChannels);
    process.start("cmd /c .agent.sh.cmd > x.txt");
    process.waitForFinished();

    QByteArray outText = process.readAllStandardOutput();

             << The value of outText is "hostname.exe not found or not internal /external / batch command".
    

    In the shell script below, c:\windows\system32\hostname.exe runs, but not hostname.exe.
    Why is this happening when the path is well set up?

    < Script File : .agent.sh.cmd >
    @echo off
    echo %PATH%
    echo "c:\windows\system32\hostname.exe"
    c:\windows\system32\hostname.exe
    echo "hostname.exe"
    hostname.exe

    < Result File : x.txt >
    C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files\Bandizip\7z;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Program Files (x86)\Microsoft Visual Studio 12.0;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
    "c:\windows\system32\hostname.exe"
    HP430-PC
    "hostname.exe"

    A 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      This is not so Qt related.. but
      The other hostname.exe is that Another copy in another location or
      do you mean the one in
      c:\windows\system32\hostname.exe
      ?

      --

      IT cannot find the hostname.exe you talk about there.
      If you have another, then u need path for it.

      DaryongD 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        This is not so Qt related.. but
        The other hostname.exe is that Another copy in another location or
        do you mean the one in
        c:\windows\system32\hostname.exe
        ?

        --

        IT cannot find the hostname.exe you talk about there.
        If you have another, then u need path for it.

        DaryongD Offline
        DaryongD Offline
        Daryong
        wrote on last edited by Daryong
        #3

        @mrjj Hi, Thanks for the response.

        Hostname.exe is known to be a command included in windows os.
        In addition to hostname.exe, other commands such as ipconfig.exe are not executed.

        At the windows command prompt, the shell will run fine.
        **) See bolded text below

        C:\>cmd /c .agent.sh.cmd > x.txt

        C:\>type .agent.sh.cmd
        @echo off
        echo %PATH%
        echo "c:\windows\system32\hostname.exe"
        c:\windows\system32\hostname.exe
        echo "hostname.exe"
        hostname.exe

        C:\Projects\sungwoo\netMon\x64\Debug\agent\shell>type x.txt

        C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:
        \Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\Window
        sPowerShell\v1.0;C:\Program Files (x86)\Intel\Intel(R) Management Engine Compon
        ents\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Pro
        gram Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program File
        s\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Microso
        ft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\Tools\Bi
        nn;C:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Program Files (x86)\W
        indows Kits\8.1\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Serv
        er\110\Tools\Binn;C:\Program Files\Bandizip\7z;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bi
        n
        "c:\windows\system32\hostname.exe"
        HP430-PC
        "hostname.exe"
        HP430-PC

        1 Reply Last reply
        0
        • DaryongD Daryong

          Hello.
          Look at the simple source below. please..

          < source >
          QProcess process;

          process.setProcessChannelMode(QProcess::MergedChannels);
          process.start("cmd /c .agent.sh.cmd > x.txt");
          process.waitForFinished();

          QByteArray outText = process.readAllStandardOutput();

                   << The value of outText is "hostname.exe not found or not internal /external / batch command".
          

          In the shell script below, c:\windows\system32\hostname.exe runs, but not hostname.exe.
          Why is this happening when the path is well set up?

          < Script File : .agent.sh.cmd >
          @echo off
          echo %PATH%
          echo "c:\windows\system32\hostname.exe"
          c:\windows\system32\hostname.exe
          echo "hostname.exe"
          hostname.exe

          < Result File : x.txt >
          C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files\Bandizip\7z;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Program Files (x86)\Microsoft Visual Studio 12.0;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
          "c:\windows\system32\hostname.exe"
          HP430-PC
          "hostname.exe"

          A Offline
          A Offline
          ambershark
          wrote on last edited by ambershark
          #4

          @Daryong said in When running cmd.exe from window 7.x to QProcess.. Not work path environment...:

          Hello.
          Look at the simple source below. please..

          < source >
          QProcess process;

          process.setProcessChannelMode(QProcess::MergedChannels);
          process.start("cmd /c .agent.sh.cmd > x.txt");
          process.waitForFinished();

          First thing I noticed is you are not using QProcess properly. You need to pass arguments separately from the executable. See http://doc.qt.io/qt-5/qprocess.html.

          I don't know if this will fix your problem, but try:

          QProcess process;
          process.setProcessChannelMode(QProcess::MergedChannels);
          process.start("cmd.exe", QStringList << "/c" << ".agent.sh.cmd" << ">" << "x.txt");
          process.waitForFinished();
          

          As for your actual issue, what happens when you hit window+r and run "cmd /k .agent.sh.cmd"? Does it work there but not in QProcess?

          You can also try setting the path like so:

          // ...
          QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
          env.insert("Path", "yourpath");
          process.setProcessEnvironment(env);
          

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          DaryongD 1 Reply Last reply
          1
          • A ambershark

            @Daryong said in When running cmd.exe from window 7.x to QProcess.. Not work path environment...:

            Hello.
            Look at the simple source below. please..

            < source >
            QProcess process;

            process.setProcessChannelMode(QProcess::MergedChannels);
            process.start("cmd /c .agent.sh.cmd > x.txt");
            process.waitForFinished();

            First thing I noticed is you are not using QProcess properly. You need to pass arguments separately from the executable. See http://doc.qt.io/qt-5/qprocess.html.

            I don't know if this will fix your problem, but try:

            QProcess process;
            process.setProcessChannelMode(QProcess::MergedChannels);
            process.start("cmd.exe", QStringList << "/c" << ".agent.sh.cmd" << ">" << "x.txt");
            process.waitForFinished();
            

            As for your actual issue, what happens when you hit window+r and run "cmd /k .agent.sh.cmd"? Does it work there but not in QProcess?

            You can also try setting the path like so:

            // ...
            QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
            env.insert("Path", "yourpath");
            process.setProcessEnvironment(env);
            
            DaryongD Offline
            DaryongD Offline
            Daryong
            wrote on last edited by Daryong
            #5

            @ambershark

            Hello.
            I think I have found the cause of the problem. There seems to be a bug in qt.

            The path of QProcess differs from the path of the system, but this is not a big problem.
            By the way, it seems that some paths are disabled by "(double quotation marks) in the path of QProcess::processEnvironment(). Please check..

            I set the path as shown below and it works fine.

            QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
            env.insert("Path", env.value("Path").remove("\"") );
            process.setProcessEnvironment(env);

            < System Env Path >

            C:\Users\HP430>echo %PATH%

            C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:
            \Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\Window
            sPowerShell\v1.0;C:\Program Files (x86)\Intel\Intel(R) Management Engine Compon
            ents\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Pro
            gram Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program File
            s\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Microso
            ft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\Tools\Bi
            nn;C:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Program Files (x86)\W
            indows Kits\8.1\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Serv
            er\110\Tools\Binn;C:\Program Files\Bandizip\7z;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bi
            n

            < QProcess::processEnvironment() - Path >

            C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;"C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;"C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;"C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;"C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;"C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files\Bandizip\7z;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Program Files (x86)\Microsoft Visual Studio 12.0;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64

            A 1 Reply Last reply
            0
            • DaryongD Daryong

              @ambershark

              Hello.
              I think I have found the cause of the problem. There seems to be a bug in qt.

              The path of QProcess differs from the path of the system, but this is not a big problem.
              By the way, it seems that some paths are disabled by "(double quotation marks) in the path of QProcess::processEnvironment(). Please check..

              I set the path as shown below and it works fine.

              QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
              env.insert("Path", env.value("Path").remove("\"") );
              process.setProcessEnvironment(env);

              < System Env Path >

              C:\Users\HP430>echo %PATH%

              C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:
              \Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\Window
              sPowerShell\v1.0;C:\Program Files (x86)\Intel\Intel(R) Management Engine Compon
              ents\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Pro
              gram Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program File
              s\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Microso
              ft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\Tools\Bi
              nn;C:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Program Files (x86)\W
              indows Kits\8.1\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Serv
              er\110\Tools\Binn;C:\Program Files\Bandizip\7z;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bi
              n

              < QProcess::processEnvironment() - Path >

              C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;"C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;"C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;"C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;"C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;"C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\Tools\Binn;C:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files\Bandizip\7z;C:\Qt\Qt5.5.0\5.5\msvc2013_64\bin;C:\Program Files (x86)\Microsoft Visual Studio 12.0;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64

              A Offline
              A Offline
              ambershark
              wrote on last edited by
              #6

              @Daryong I don't know about the quote (") thing but the other part isn't a bug. Processes don't usually inherit the system path.

              The only things that use the system path are explorer and cmd. And other windows components. So having to set up the path with a QProcessEnvironment before use makes sense to me. That's why it's there. :)

              Glad things are working now, don't forget to mark this as solved for others.

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              1 Reply Last reply
              0

              • Login

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