Windows Qt Invoke batch file and exit the App - c++

I am developing an application in Windows8 using Qt, where I need to create an updater for it. I have Already wrote the update downloader part, and an update script to replace all the previous content with newly downloaded data.
Now I need to execute the bat file from the application itself, and exit the app before the script get executed, because the script going to remove all the dlls and application binary currently I am running.
How can I resolve this issue?
Thanks
Haris

You can use QProcess::startDetached to run an instance of command prompt with the batch file as the argument in a new process and detach from it. After that you should exit the application :
QProcess::startDetached("cmd.exe", QStringList() << "/c" << "path\\to\\mybat.bat");
qApp->quit();

Related

Unable execute external process from CGI C++

I have a problem about call external process from CGI C++.
I want to run a macro (*.xls file) from CGI code directly but it's not working. I just see the EXCEL.exe process existing in the task manager (CGI run on APACHE). When I have run it on the command line then it worked.
system("start excel \"C:\Temp\91a3e34f-e2e4-442f-af32-4a38bef95a8e\FrfmMod91a3e34f-e2e4-442f-af32-4a38bef95a8e.xls\"");
Does anybody help me?

How to run an exe file in a completely hidden way

I'm able to execute an exe file via command prompt using below line:
process = subprocess.Popen("LogCollector.EXE ")
But the LogCollector.EXE GUI is still visible, Please suggest some method to run this completely in hidden way.
import os
os.system('start /MIN notepad.exe');
Use this command in the window, it will run the application and minimize the application.
Maybe it will help you

Startup Multichain in WIndows Task Scheduler

I run command:
multichaind mychain -deamon
to start up the multichain program.
As per: https://www.multichain.com/developers/creating-connecting/
I'm running on Win 2012. I have tried putting this in a startup script using Windows Task Scheduler so that when the machine reboots, it will restart.
The task scheduler history shows it ran successfully, but it's not running. When I run the command
multichain-cli mychain getinfo
it says it cannot connect to the server.
And of course, that same command works when I start up multichain in a separate command prompt window.
My theory is that the command runs, but then the command windows is closed, but needs to remain open. Is there any way to do this, or debug what is going on?
I tried adding the parms as:
mychain -daemon >>d:\Software\Multichain\log.txt
hoping that it would write to the file so I could read it. But no file was created.
Update: I tried the .cmd file approach as recommended in the comment:
multichaind mychain -daemon
pause
That doesn't make sense to me because the first line should never finish.
It did create the log.txt file, but the whole thing still ran and quit in a few seconds:
d:\Software\Multichain>multichaind mychain -daemon 1>>d:\Software\Multichain\log.txt
d:\Software\Multichain>pause
Press any key to continue . . .

Cannot launch Microsoft Management Console snap-in from Qt

I'm trying to run a program with another program. For this I use a class QProcess.
Program must be run with administrator privileges. To keep things simple step debugging and lead an example here, I started qt creator with privileges administator.
Now the fun part.
The following code runs the calculator.
QProcess * p = new QProcess();
p->start("C:\\Windows\\System32\\calc.exe");
p->waitForStarted();
delete p;
This code works.
Now another example, which already runs the service window windows.
QProcess * p = new QProcess();
p->start("C:\\Windows\\System32\\services.msc");
p->waitForStarted();
delete p;
This code does not run the program services.msc. File exists and is run from the command line without any problems.
Why one works and the other not? How to fix?
Windows 7 x86.
Short answer: .msc is not an executable file type.
Long answer:
.msc is what's called a snap-in for the Microsoft Management Console.
From the command prompt or even from Start -> Run (win + R), running services.msc tells the operating system Hey, run this file with whatever program is associated with .msc files.
That program in particular is called mmc.exe, and even when run services.msc from the command prompt and look in the Task Manager, you'll see the window actually belongs to services.exe.
Try to start either mmc.exe services.msc or cmd.exe /C services.msc instead.

C++ Keep process alive after it kills its parent

I'm working on implementing a self-updater for a daemon on OS X. The update is published as a .pkg file, so what I'm trying to do is as follows:
When the daemon is notified that an update is available, it calls installer via the system() call to install the package. The package contains a newer version of the daemon, a preupgrade script that stops the daemon (launchctl unload /Library/LaunchDaemons/foo.plist), and a postflight script that starts it back up after the new version is installed. The problem I'm having is that the installer process is quitting prematurely. I suspect that it may be because the installer kills its parent process in order to update it, and then gets killed itself instead of continuing as its own orphan process. I've tried the following with no luck:
Postpending the installer command with '&' to run it in the
background
Wrapping the installer command with nohup
The install command completes consistently without error when I run it from the command line, and fails consistently when run from the installer. When called from the installer, I'm piping the output to a file, and sometimes it has nothing, and sometimes it shows the install getting to about 41% completion before output stops. Any ideas on how I can figure out what's happening to the process or make sure it stays alive without its parent?
When you call launchctl unload, it kills the entire process group (unlike a simple kill). You want to move your subprocess into a separate process group. The easiest way is with the C call setsid().
If you're in the middle of a shell script, you should look at the following approaches. I haven't tried these since I was dealing with a C program and could setsid():
Prior to calling the installer, use set -m. This is supposed to turn on monitor mode, which says "Background processes run in a separate process group and a line containing their exit status is printed upon their completion."
Try this sub-interative shell trick: New process group in shell script