Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. qprocess
    Log in to post

    • UNSOLVED QProcess not printing "live update" from cmd
      General and Desktop • qprocess • • Dariusz  

      15
      0
      Votes
      15
      Posts
      161
      Views

      @Dariusz said in QProcess not printing "live update" from cmd: sftp sends messges like But (so far as I can see) you know it does that only when output is attached to a terminal/console. Which their code may be testing for, and not sending if not. Because there is no \n, the qt does not trigger any signals. Not byteavailable or anything really as far as I can tell. The presence or absence of \n will not itself affect whether Qt/QProcess sees or receives bytes. It might be an indication that it is not being flushed immediately, but that is a different matter. I take when we self.process.setProcessChannelMode(QProcess.ForwardedChannels) he then get console somehow? I believe that attaches the QProcess's output to the output of the Qt program, which is a console/terminal. Which as I say may be why in that case, and only that case, you see the output. But then you won't be able to "capture" it. Can you link me to post/text? I'm blind :- ( Principal among these was Try running your sftp from a Command Prompt but with all its output redirected to a file. When it has finished what is in that file, any "status messages"? You should test something like: sftp < file_of_input_commands > some_file If you can also redirect Windows/DOS/cmd stderr that would be even better. Like under Linux it would be sftp < file_of_input_commands > some_file 2>&1 but I can't recall whether/how you can do that 2>&1-type thing with Windows. Test without that anyway. The point here is that output should not be left to go to console. This is close to simulating what is going on when you have another program --- Qt or not --- running a sub-process with redirection. I have a hunch this will show that in this situation you do not get the "update" messages, because sftp program detects the output redirection and does not issue them in this case.....
    • SOLVED QProcess not reading process output
      General and Desktop • linux qprocess qdebug terminal program • • camtheman99  

      9
      0
      Votes
      9
      Posts
      184
      Views

      @camtheman99 That is interesting, thanks to @Christian-Ehrlicher.
    • SOLVED QProcess returns "wrong" result due to architecture, mac.
      General and Desktop • qprocess mac arm architecture • • Dariusz  

      2
      1
      Votes
      2
      Posts
      92
      Views

      Hi, You can open a feature request to discuss that matter.
    • SOLVED QProcess not working in QT Creator (using qt version 6.3.0)
      General and Desktop • qt creator qprocess qt 6.3.0 • • BigBen  

      4
      0
      Votes
      4
      Posts
      168
      Views

      @BigBen said in QProcess not working in QT Creator (using qt version 6.3.0): However, p->startCommand("dir C:\\Users") gives me no error and no output. Well that is interesting. As I said I only just discovered looking at the docs. It's new in Qt 6.0. I do not use Qt 6, nor Windows, so I cannot comment. If you look at he examples at https://doc.qt.io/qt-6/qprocess.html#startCommand you can see them claiming to issue dir commands that way, that's all I can say. I want to ask that in p->start("cmd", { "/c", "dir C:\\Users" });, what does the /c mean in the second argument? The Windows/DOS cmd.exe takes various arguments, as you can see from running cmd /?. Including: /C Carries out the command specified by string and then terminates Basically without the /c it runs an interactive Command Prompt, the command-line console. With the /c it interprets and executes the command line string following it, i.e. your dir .... It does not open a Command Prompt window and it returns to your code immediately after executing the command. dir is built into cmd.exe --- along with many other "simple" commands like echo or mkdir --- there is no external dir.exe file to execute, so we need cmd /c dir to perform it.
    • SOLVED Why external Makefile not working in Qt project?
      Qt 6 • qprocess makefile linker errors system g++ • • OroszB  

      5
      0
      Votes
      5
      Posts
      209
      Views

      I solved it, the makefile contains this command as well: flex MyLanguage.l and in the OS there is two intalled flex, Qt used the wrong one.
    • SOLVED EnumWindows not finding hWnd from PID if program is started using QProcess
      General and Desktop • qprocess win32 hwnd enumwindows • • Waoweens  

      17
      0
      Votes
      17
      Posts
      379
      Views

      Looks like using the QProcess::stateChanged signal (and removing terminate()) works. It uses QThread::msleep() so its not ideal, but its fine for me. HWND myHWND; static BOOL CALLBACK enumWindowCallback(HWND hWnd, LPARAM lparam) { DWORD pid; GetWindowThreadProcessId(hWnd, &pid); if (pid == lparam) { myHWND = hWnd; return FALSE; } return TRUE; } ProgramStarter::ProgramStarter(QObject *parent) : QObject{parent} { QProcess *qpr = new QProcess(this); connect(qpr, &QProcess::stateChanged, this, [=](QProcess::ProcessState newState){ if (newState == QProcess::Running) { QThread::msleep(250); EnumWindows(enumWindowCallback, qpr->processId()); } }); QString executable = "C:\\path\\to\\program.exe"; qpr->start(executable); qDebug() << myHWND; }
    • SOLVED QProcess: run app via sudo
      General and Desktop • qprocess sudo • • debian  

      9
      0
      Votes
      9
      Posts
      413
      Views

      $ /usr/sbin/getcap /bin/ping /bin/ping cap_net_raw=ep This work because /bin/ping have capabilites https://man7.org/linux/man-pages/man7/capabilities.7.html CAP_NET_RAW Use RAW and PACKET sockets; bind to any address for transparent proxying.
    • SOLVED With QProcess startet python script not working
      General and Desktop • qprocess • • firen  

      10
      0
      Votes
      10
      Posts
      287
      Views

      @JonB Thanks. I like the QStandardPaths::StandardLocation but I did a deploy and after that I put just everythink in the folder with the *.exe file like @eyllanesc suggested and it works fine. I think my problem was that i missunderstood QProcess. I thought it is just a trigger to start the program and it is only important to know, where the path of the .py is. But thanks guys anyway :-)
    • UNSOLVED Converting QByteArray to QString
      General and Desktop • qprocess qstring qbytearray • • Sina Ranjkesh zade  

      13
      0
      Votes
      13
      Posts
      1741
      Views

      @Sina-Ranjkesh-zade said in Converting QByteArray to QString: For "standard input" if you mean input arguments of the process, I got this error: No, I meant standard input. That is , the python program reads from a terminal and accepts input just as if you typed it (except it is the Qt program sending that input). The Qt program can send a command to the python program, send the data it needs, and read the result (if there is one) back on the python program's standard output. Or you can used shared memory, or a socket, or files, or do whatever the python program is doing in the Qt program...
    • UNSOLVED Run a terminal command with a button click
      General and Desktop • qprocess ubuntu terminal command ros • • aliemrenebiler  

      2
      0
      Votes
      2
      Posts
      397
      Views

      @aliemrenebiler said in Run a terminal command with a button click: QProcess is not working, the program never opens and says as output "QProcess: Destroyed while process ("...") is still running.". The problem would appear to be that your QProcess object goes out of scope (is destroyed) while the process you asked it to launch is still running i.e. exactly what the error message says. This is most likely because you have create the QProcess on the stack in the slot handling your button click, but it could be because it is parented to another QObject that is destroyed. We can only guess without seeing your code.
    • UNSOLVED After testing under windows, it is found that QT program will kill the process created by CreateProcess when it exits again
      General and Desktop • qprocess • • legahero  

      4
      0
      Votes
      4
      Posts
      224
      Views

      @JKSH ,thanks,I find that this happens when debugging, not when publishing。
    • SOLVED How to redirect stdout/etc of detached QProcess
      General and Desktop • qprocess • • Dariusz  

      11
      0
      Votes
      11
      Posts
      744
      Views

      @JonB Wait really !? I could swear that they were blocking methods hmmmmmmmmmmmmmmmmmmmmmmmmmmmmm my bad! Thanks :D
    • SOLVED QProcess startDetached() run ps1 script
      General and Desktop • qprocess script startdetached powershell ps1 • • Piotrek102  

      8
      0
      Votes
      8
      Posts
      464
      Views

      @SGaist Great idea! I change the code and everything should work. I close the topic and if I encounter any other problems I will create a new one. @SGaist , @JoeCFD Thank you for your help!
    • SOLVED QML start external program: use QProcess fail build
      QML and Qt Quick • qml qprocess build failed • • warcomeb  

      4
      0
      Votes
      4
      Posts
      655
      Views

      @J-Hilk Thanks for your help! It works!
    • UNSOLVED QProcess does not recognize input path with accent
      General and Desktop • c++ qprocess windows10 • • xchess64  

      8
      0
      Votes
      8
      Posts
      497
      Views

      @JonB: yes, and then use QString::fromUtf8()
    • UNSOLVED Using QTquick 1 to trigger a bash script on button click
      QML and Qt Quick • qprocess qt4 process qtquick1.1 • • jcthomas556  

      5
      0
      Votes
      5
      Posts
      349
      Views

      @JonB This is a quote from the example given on the link listed. It's from QT, in an explanation of how this works. It's not a string that I came up with, or that I'm using.
    • UNSOLVED Can't kill QProcess in overriden closeEvent()
      General and Desktop • qprocess qcloseevent • • nikko1991  

      12
      0
      Votes
      12
      Posts
      783
      Views

      @nikko1991 said in Can't kill QProcess in overriden closeEvent(): I believe shutting down ROS from Qt/other program is slower than from terminal I don't claim to understand what you are saying in your post, and I probably won't understand even if you try to explain more! But I do not know what you could mean by this sentence. The "terminal" (i.e. a "shell") simply is "from other program". There is no difference between a shell and any other program under Linux, and if you can do something from a shell you can do it from a program you write. As a separate matter, I wouldn't use the blocking QProcess::waitFor...() methods anyway, at least not in the case of issues with the program spawned. There is no need to, as there are the asynchronous signals from QProcess available to you, which is how the waitFor()s are implemented anyway. So if you are saying these are causing you problems, don't use them.
    • SOLVED Qprocess reading execution output Simentensously
      General and Desktop • qprocess qtcore command line shell • • Amirhos  

      9
      0
      Votes
      9
      Posts
      733
      Views

      @Amirhos Unfortunately this is difficult, especially under Windows. If, for whatever reason, the third-party app is buffering its output at its own side then you cannot force it down the pipe to your parent, it depends how the code is written at their side....
    • UNSOLVED Sending curl command to command prompt using QProcess
      General and Desktop • c++ qprocess api curl • • Ahsan Niaz  

      20
      0
      Votes
      20
      Posts
      1313
      Views

      I am really thankful to everyone who replied to me and corrected my mistakes. Your help will help me finish my work quicker. Thanks @Christian-Ehrlicher , @Bonnie @JonB
    • SOLVED Qprocess runs correctly in debug but in release mode it doesn't run correctly
      General and Desktop • qprocess linux chromeos waitforfinished • • TahmDev  

      11
      0
      Votes
      11
      Posts
      817
      Views

      @SGaist as a matter of fact it did... Then I used Qthread::msleep(500); I will try using it asynchronously today and get back to you with the result...
    • UNSOLVED Detaching from process
      General and Desktop • qprocess • • Massimiliano75  

      11
      1
      Votes
      11
      Posts
      908
      Views

      @JonB sorry if i reply now, but my company has closed for a week, launching a script was an example, any qprocess gives me that message also if i start ls, arp-scan or others. if i start a program locally i don't have this problem, the problem occurs if i start a program in remote debug, but the versions (local and remote) of gdb and linux are the same
    • SOLVED Opening command shell when starting a Qprocess
      General and Desktop • c++ qprocess exe command line • • JCSB  

      5
      0
      Votes
      5
      Posts
      367
      Views

      @SGaist Thank you, this has solved my issue!! :D
    • UNSOLVED Using QProcess to Create Mock Command Prompt
      General and Desktop • qprocess command line command • • cstevenson  

      8
      0
      Votes
      8
      Posts
      604
      Views

      @cstevenson Please also connect a slot to https://doc.qt.io/qt-5/qprocess.html#errorOccurred The process is probably not running when you call write().
    • SOLVED QProcess waitForFinish exits immediately
      General and Desktop • python qprocess script output • • Kyeiv  

      7
      0
      Votes
      7
      Posts
      755
      Views

      @Kyeiv OK, but please put the error checking code in anyway. With OS commands you never know what might go wrong (just like you discovered), so it's important to check for & report all errors! And especially if you are going to be distributing this....
    • UNSOLVED QProcess with powershell command still running
      General and Desktop • qprocess powershell • • TomNow99  

      11
      0
      Votes
      11
      Posts
      1088
      Views

      The problem might be that you have two nested calls to PowerShell without exiting them. A quick search shows people reporting the inner PowerShell call (with -Verb runas) keeps the console window open. So, instead of the netsh command you might want to provide a script that has the netsh command and an exit. Or maybe you can concatenate the two directly in the -ArgumentList (I don't have much experience with PowerShell, but in Linux I could separate commands with a semicolon).
    • SOLVED Access to Windows network shared folder from linux
      General and Desktop • linux qprocess mount network shared • • Francis Chapet  

      8
      0
      Votes
      8
      Posts
      746
      Views

      @mrjj ...Which is one of the 1,000 reasons I would not be accepting this Qt application if it says I need to run it sudo... :)
    • SOLVED crash at GetExitCodeProcess in qprocess_win.cpp
      General and Desktop • qprocess windows 10 • • thamht4190  

      5
      0
      Votes
      5
      Posts
      406
      Views

      Thanks @JonB . The problem seems gone when I remove these "process terminate" code.
    • UNSOLVED Problem recording webcam with FFMPEG and QProcess
      General and Desktop • qprocess fmpeg webca • • Guigiidre  

      9
      0
      Votes
      9
      Posts
      813
      Views

      @jsulm I did :-) but I have no more information... Anyway I will stop using the QProcess class to reccord video with my webcam, it seems too tricky, instead I think I will use a library like LibVLC to do it...
    • SOLVED why QProcess is not working in MAC os?
      General and Desktop • qprocess bundle macros qt 5.11.0 • • Yash001  

      19
      0
      Votes
      19
      Posts
      3045
      Views

      @JonB Thank you for correct direction. I will modify my code and use it finished Signal for updating dialog box.
    • SOLVED QProcess not reading stdout
      General and Desktop • c++ qprocess stdout • • CaffeinatedGecko  

      5
      0
      Votes
      5
      Posts
      1943
      Views

      @JonB Thanks! That saved me a good deal of troubleshooting. It turned out the problem was a hard path to a file inside the C program which caused it to run correctly when invoked from it's native directory, but caused a segfault when called by Qt since the paths were different. The problem is completely fixed now.
    • SOLVED The true meaning of the warning for QProcess::waitForFinished
      General and Desktop • qprocess gui freeze waitforfinished document • • Shinichiro  

      10
      0
      Votes
      10
      Posts
      1988
      Views

      Hi, Thank you for your reply. I totally changed my implementation using the signal and slots. Thank you so much again.
    • SOLVED QProcess for a Sudo, dd Command and a Pipe for md5sum
      General and Desktop • qprocess sudo pipe • • BitFlipper  

      8
      0
      Votes
      8
      Posts
      2463
      Views

      @BitFlipper b) I tried that already with no luck Then you did not try right! There is an example of just what you need at the link I posted. The outline of this approach would be: QProcess ddProcess, md5sumProcess; ddProcess.setStandardOutputProcess(&md5sumProcess); ddProcess.start("sudo dd if=/dev/sda2 of=/dev/sdb2 bs=4096 conv=noerror"); md5sumProcess.start("md5sum"); md5sumProcess.waitForFinished(); However, it's probably more suitable for you to issue the whole lot as a single string passed to /bin/sh or /bin/bash with the -c argument, and let it figure the | for you., as per my example earlier. So my command changes in this function, should I build a custom string every time and pass it in as one statement? Yes. I always practice in terminal first For this purpose make yourself use /bin/sh -c "sudo dd ... | md5sum" as that is what you will need. Be careful if anything in your command requires its own quoting (your current example does not), as the whole command itself is now inside quotes. As I wrote earlier, your md5sum is not going to see the contents from the dd. Your example does not lend itself to checksumming as it uses a single dd if=... of=... which does the input & output in one go. What you want is for the output from the dd to go both to the output file and to md5sum. Here are two possibilities for you to play with: sudo dd if=/dev/sda2 bs=4096 conv=noerror | sudo tee /dev/sdb2 | md5sum sudo dd if=/dev/sda2 bs=4096 conv=noerror | tee >(md5sum 1>&2) | sudo dd of=/dev/sdb2 bs=4096 In the first case we tee the output off to /dev/sdb2 as well as letting it through to md5sum. Simpl-ish, but you lose the ability to specify the bs= for the output to /dev/sdb2. I don't know if that matters to you. In the second case you use "shell magic" (you'll probably have to use /bin/bash not /bin/sh, I think) to send tee's output to md5sum process as well as passing it onto a second dd to do the output. I have made it so md5sum's output goes to standard error instead of standard output. Finally: is all this dd and checksum stuff worth it? Probably not. Have a read of, say, https://unix.stackexchange.com/a/45854/104736 for alternative suggestions.
    • UNSOLVED Calling kextunload / kextload on mac (need sudo privilege)
      General and Desktop • qprocess sudo administrator privileges kext • • AloyseTech  

      3
      0
      Votes
      3
      Posts
      598
      Views

      Hi, I have found something that works but that is not really "clean" in my opinion : QString password = "yourRootPassword"; //could be asked with QInputDialog::getText(...) QString cmd = QString("sudo -S kextunload -b %1 > /dev/null").arg(driverName); FILE *pipe = popen(cmd.toStdString().c_str(), "w"); if(pipe != nullptr) { fprintf(pipe, "%s\n", password.toStdString().c_str()); if (ferror(pipe)) { qDebug() << "Failed to write to pipe"; } else { qDebug() << "Written to pipe"; } } else { qDebug() << "Failed to open pipe"; } qDebug() << "Pipe returned : " << pclose(pipe); I don't know how to use the Apple method linked by SGaist...
    • UNSOLVED how to feed data to Qt creator ( plugin development )
      General and Desktop • qtcreator plugin qprocess c++11 • • Qjay  

      4
      0
      Votes
      4
      Posts
      772
      Views

      thanks !! . I will look into both of them
    • SOLVED Qprocess not taking proper arguments
      General and Desktop • qt creator qprocess qtcore • • Qjay  

      10
      0
      Votes
      10
      Posts
      1839
      Views

      You might have modified PATH in your terminal session only for example. Or you may have modified PATH in the Run part of the Project panel.
    • SOLVED Problems with providing arguments to QProcess
      General and Desktop • qprocess desktop qt4 qstringlist • • Thanos  

      6
      0
      Votes
      6
      Posts
      5519
      Views

      @Thanos thanks for your feedback. So please mark this topic as SOLVED now.
    • UNSOLVED Communicating with Eternal C++ Project using QT Widgets Application
      Tools • qt creator qwidget cmake qprocess external proces • • Ghaas  

      2
      0
      Votes
      2
      Posts
      759
      Views

      Hi and welcome to devnet, You should take a look at the various IPC options provided by Qt.
    • UNSOLVED Web server started through QProcess is unable to receive GET requests
      General and Desktop • qprocess server http get environment • • Red Baron  

      22
      0
      Votes
      22
      Posts
      3559
      Views

      IIRC, you have QTest;:wait for that kind of stuff.
    • UNSOLVED QProcess: start a compiled c program and output to textBrowser in Linux
      General and Desktop • linux qprocess execute c program textbrowser • • Naim  

      13
      0
      Votes
      13
      Posts
      3327
      Views

      @Naim Use http://doc.qt.io/qt-5/qprocess.html#readyReadStandardOutput and http://doc.qt.io/qt-5/qprocess.html#readyReadStandardError to get notifications each time the process writes something to stdout or stderr and read it using http://doc.qt.io/qt-5/qprocess.html#readAllStandardOutput and http://doc.qt.io/qt-5/qprocess.html#readAllStandardError. Do not call waitForFinished, just make sure your proc does not go out of scope (make it class member).