Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QProcess::start doesn't display a console window for console programs (Windows)

    General and Desktop
    3
    17
    17022
    Loading More Posts
    • 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.
    • V
      Violet Giraffe last edited by

      I see your point. I already figured that bare QProcess won't do what I need, so I'm experimenting with QProcess::startDetached("cmd.exe", QStringList() << "/C" << command, workingDir) strategy.

      1 Reply Last reply Reply Quote 0
      • M
        MuldeR last edited by

        So what is it that you want exactly? I still don't quite get it...

        Why not something like:
        @m_process.setProcessChannelMode(QProcess::MergedChannels);
        m_process.setReadChannel(QProcess::StandardOutput);
        connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput()));
        m_process.start( ... );@
        @MyClass::processOutput()
        {
        while(!m_process.canReadLine())
        {
        QByteArray line = m_process.readLine();
        printf("[childproc] %s\n", line.constData());
        }
        }@

        My OpenSource software at: http://muldersoft.com/

        Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

        Go visit the coop: http://youtu.be/Jay...

        1 Reply Last reply Reply Quote 0
        • V
          Violet Giraffe last edited by

          I want to have a command line in my program that would act exactly as if the commands are executed in a shell, with shell itself being launched implicitly. so if I want to launch any program I just type its name, press Enter and its window should appear, no matter console or GUI. But I should also be able to redirect output to a file with > symbol.

          1 Reply Last reply Reply Quote 0
          • M
            MuldeR last edited by

            That sounds like you are trying to workaround all the "services" QProcess offers and you just want the plain "system()":http://www.cplusplus.com/reference/cstdlib/system/ command...

            My OpenSource software at: http://muldersoft.com/

            Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

            Go visit the coop: http://youtu.be/Jay...

            1 Reply Last reply Reply Quote 0
            • V
              Violet Giraffe last edited by

              std::system would be good because I don't have to guess what shell the OS uses or which flags I need to execute my commands, but I can't set a working dir. That's crucial.

              1 Reply Last reply Reply Quote 0
              • M
                MuldeR last edited by

                system() probably uses the working dir establish by chdir().

                But if that doesn't work, you could also simply use a command like:
                @"pushd c:\my_working_dir && do_something"@

                The system() string is passed to the shell, so all shell commands work.

                __

                Anyway, if you decide to run "cmd.exe" manually, you should be using:
                "%ComSpec%":http://en.wikipedia.org/wiki/ComSpec

                My OpenSource software at: http://muldersoft.com/

                Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                Go visit the coop: http://youtu.be/Jay...

                1 Reply Last reply Reply Quote 0
                • V
                  Violet Giraffe last edited by

                  Any specific reason you've suggested pushd and not cd?

                  1 Reply Last reply Reply Quote 0
                  • V
                    Violet Giraffe last edited by

                    std::system doesn't cut it for me because it blocks until the shell exits, which is unacceptable. And I don't see a way to pass non-ASCII paths to it. So I'll have to use QProcess::startDetached after all.

                    1 Reply Last reply Reply Quote 0
                    • M
                      MuldeR last edited by

                      [quote author="Violet Giraffe" date="1399141297"]Any specific reason you've suggested pushd and not cd?[/quote]

                      Because "cd" only changes the path, not the drive. At least on Windows.

                      At the same time "push" changes the path and drive, if required.

                      [quote author="Violet Giraffe" date="1399148562"]std::system doesn't cut it for me because it blocks until the shell exits, which is unacceptable. And I don't see a way to pass non-ASCII paths to it. So I'll have to use QProcess::startDetached after all.[/quote]

                      You could invoke it in a separate thread, so it doesn't block. And if you need Unicode support, just use _wsystem() on Windows with an UTF16 string. On Linux you can use the standard system() with an UTF8 string.

                      My OpenSource software at: http://muldersoft.com/

                      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                      Go visit the coop: http://youtu.be/Jay...

                      1 Reply Last reply Reply Quote 0
                      • V
                        Violet Giraffe last edited by

                        Thanks! I've googled for wide-string analog of system(), but couldn't find it.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post