[Interest] QProcess to start a process at a higher priority

Jason Kretzer Jason at gocodigo.com
Tue Mar 10 17:59:04 CET 2015


One last thing.

I am trying to start the VBS with:

p->startDetached("go.vbs", arguments);

However, this returns false and does not start the vbs.  I see that you use cscript to start yours, but you do not pass any arguments.  How would that be accomplished?  Basically, in the line above, the arguments is a QStringList that I can pass to go.vbs.  How would I invoke cscript and pass arguments to the vbs?

-Jason

//------------------------------//
   Jason R. Kretzer
   Lead Application Developer
   Jason at gocodigo.com<mailto:Jason at gocodigo.com>
//-----------------------------//


From: "Jason R. Kretzer" <jason at gocodigo.com<mailto:jason at gocodigo.com>>
Date: Tuesday, March 10, 2015 at 12:02 PM
To: "Jason R. Kretzer" <jason at gocodigo.com<mailto:jason at gocodigo.com>>, NoMercy <nomercy at gmail.com<mailto:nomercy at gmail.com>>, "interest at qt-project.org<mailto:interest at qt-project.org>" <interest at qt-project.org<mailto:interest at qt-project.org>>
Subject: Re: [Interest] QProcess to start a process at a higher priority

Answered my own question, it appears if I just wrap the arguments in chr(34)’s it will retain the integrity of the argument.

Thanks Emre.

-Jason

//------------------------------//
   Jason R. Kretzer
   Lead Application Developer
   Jason at gocodigo.com<mailto:Jason at gocodigo.com>
//-----------------------------//


From: "Jason R. Kretzer" <jason at gocodigo.com<mailto:jason at gocodigo.com>>
To: NoMercy <nomercy at gmail.com<mailto:nomercy at gmail.com>>, "interest at qt-project.org<mailto:interest at qt-project.org>" <interest at qt-project.org<mailto:interest at qt-project.org>>
Subject: Re: [Interest] QProcess to start a process at a higher priority

Emre, thanks so much.

I do indeed have a static number of arguments.  Unfortunately, the reason they are quoted was because the arguments have spaces in them and Wscript.Arguments wants to ignore the quotes :)

-Jason

//------------------------------//
   Jason R. Kretzer
   Lead Application Developer
   Jason at gocodigo.com<mailto:Jason at gocodigo.com>
//-----------------------------//


From: NoMercy <nomercy at gmail.com<mailto:nomercy at gmail.com>>
Date: Tuesday, March 10, 2015 at 11:15 AM
To: "Jason R. Kretzer" <jason at gocodigo.com<mailto:jason at gocodigo.com>>, "interest at qt-project.org<mailto:interest at qt-project.org>" <interest at qt-project.org<mailto:interest at qt-project.org>>
Subject: Re: [Interest] QProcess to start a process at a higher priority

Hello again,
for that I have something like this (if you have a static number of arguments);

Set WshShell = CreateObject("WScript.Shell")
WshShell.currentdirectory = "C:\Program Files\your_app_dir"
'wscript.echo WshShell.currentdirectory
WshShell.Run chr(34) & "C:\Program Files\ your_app_dir\your_bat.bat" & chr(34) & " " & Wscript.Arguments(0) & " " & Wscript.Arguments(1) , 0
Set WshShell = Nothing

Happy Coding
Emre

On Tue, Mar 10, 2015 at 5:09 PM, Jason Kretzer <Jason at gocodigo.com<mailto:Jason at gocodigo.com>> wrote:
Thanks!

Honestly, I do not have much experience with Vbscript.  In your example below, how would I pass arguments to the your_bat.bat?  I have 8 quoted arguments that I need to pass the bat file.

I have tried this

Dim arg0
arg0 = WScript.Arguments.Item(0)
WScript.Echo arg0
WshShell.Run chr(34) & "C:\Program Files\yourapp\your_bat.bat" & arg0 & chr(34) , 0

But that is not quite right.  It echos the arg0 fine but I get a “The system cannot find the file specified” when I run that.

Thoughts?

-Jason

//------------------------------//
   Jason R. Kretzer
   Lead Application Developer
   Jason at gocodigo.com<mailto:Jason at gocodigo.com>
//-----------------------------//


From: NoMercy <nomercy at gmail.com<mailto:nomercy at gmail.com>>
Date: Monday, March 9, 2015 at 5:27 AM
To: "Jason R. Kretzer" <jason at gocodigo.com<mailto:jason at gocodigo.com>>
Subject: Re: [Interest] QProcess to start a process at a higher priority

Our app uses an ugly method for exactly this reason and I intend to research and find a better solution on this subject when I have time but for the moment we use "cscript.exe /path/to/your/script.vbs"
in vbs:

Set WshShell = CreateObject("WScript.Shell")
WshShell.currentdirectory = "C:\Program Files\ yourapp"
'wscript.echo WshShell.currentdirectory
WshShell.Run chr(34) & "C:\Program Files\yourapp\your_bat.bat" & chr(34) , 0
Set WshShell = Nothing

And if I'm remembering correctly the zero ("0") at the end of line that starts with "WshShell.Run" makes it windowless.

Happy coding
Emre

On Mon, Mar 9, 2015 at 1:53 AM, Jason Kretzer <Jason at gocodigo.com<mailto:Jason at gocodigo.com>> wrote:
Hello all,

I am tinkering a bit with QProcess on Windows7.  What I would like to be able to do is to start a process with a “high” priority.  My application spawns multiple processes and I am tinkering with them in order to help ensure they get their processor time.

On the command line, I would do this.

start /high myspawn.exe arg1 arg2 arg3

Unfortunately one of the requirements is that a DOS window not open to run it.

If I start the process like this:

QString program = “myspawn.exe";
QStringList arguments;

arguments << “arg1” << “arg2" << “arg3";

QProcess *p = new QProcess(this);
QTimer::singleShot(30000, this, SLOT(deleteLater()));
qDebug() << "starting mysawn process -- " << p->startDetached(program, arguments);

It starts just fine, no DOS window, but at Normal priority.

I have tried multiple ways using the “start /high…” command inside of the various ways to execute a command with QProcess, but they always flash a DOS window.

I even create a .bat file with the command in it and passed arguments in with the above code.  While it worked, it flashed the DOS window.

Am I missing something here?

-Jason

//------------------------------//
   Jason R. Kretzer
   Lead Application Developer
   Jason at gocodigo.com<mailto:Jason at gocodigo.com>
//-----------------------------//


_______________________________________________
Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>
http://lists.qt-project.org/mailman/listinfo/interest


________________________________

No virus found in this message.
Checked by AVG - www.avg.com<http://www.avg.com>
Version: 2015.0.5645 / Virus Database: 4299/9221 - Release Date: 03/03/15

________________________________

No virus found in this message.
Checked by AVG - www.avg.com<http://www.avg.com>
Version: 2015.0.5645 / Virus Database: 4299/9221 - Release Date: 03/03/15

________________________________

No virus found in this message.
Checked by AVG - www.avg.com<http://www.avg.com>
Version: 2015.0.5645 / Virus Database: 4299/9221 - Release Date: 03/03/15

________________________________

No virus found in this message.
Checked by AVG - www.avg.com<http://www.avg.com>
Version: 2015.0.5645 / Virus Database: 4299/9221 - Release Date: 03/03/15
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150310/7827e8e8/attachment.html>


More information about the Interest mailing list