I want to create a user command using 'Open' or 'Open with' to optimize PNG images using PngOut.
So, I have the 'PngOut.exe' executable, but it only accepts 1 file name per invocation. When I use the 'Open with' command with the 'Multiple instance' setting and the '<items>' parameter, XyPlorer starts all the commands at the same time. So, selecting 100 files means that XyPlorer will start PngOut 100 times at the same time!
This is obviously enough for a hard reset of my computer, because Windows totally dies on me.
How do I start 1 after another (synchronously) instead of all at once (asynchronously).
Any help would be highly appreciated.
[Solved] How do I synchronously execute commands?
-
Sander Bouwhuis
- Posts: 249
- Joined: 10 Jun 2008 15:40
- Location: Netherlands
[Solved] How do I synchronously execute commands?
Last edited by Sander Bouwhuis on 17 Jul 2011 14:11, edited 1 time in total.
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: How do I synchronously execute commands?
I don't think there is a build in solution for this kind of task (if you work with multiple selected files).
The normal way (for me) is to use writeline() to build a batch file and execute it at the end of the (xyplorer) script with open().
The normal way (for me) is to use writeline() to build a batch file and execute it at the end of the (xyplorer) script with open().
One of my scripts helped you out? Please donate via Paypal
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: How do I synchronously execute commands?
Seams to me the openwith() as command and also in UDC missed an Wait=1 parameter.iycgtptyarvg wrote:When I use the 'Open with' command with the 'Multiple instance' setting and the '<items>' parameter, XyPlorer starts all the commands at the same time. So, selecting 100 files means that XyPlorer will start PngOut 100 times at the same time!
Maybe this could be an improvement wish to Donald:
openwith application, [mode (s|m|W)], [item]
where 'w' is the same as 'm' but will wait till the called process has finished the task right before.
In the meantime....
You can use an UDC with "Run Script"How do I start 1 after another (synchronously) instead of all at once (asynchronously).
and use an script like this example:
Code: Select all
$SelFiles = get("SelectedItemsPathNames", "|");
foreach($file, $SelFiles){
$file = quote($file);
msg "run myExe with $file as parameter",1;
///// run command, [directory], [wait=0 (0=return immediately, 1=wait till the process has finished)]
// run notepad $file,,1;
}HTH?
-
Sander Bouwhuis
- Posts: 249
- Joined: 10 Jun 2008 15:40
- Location: Netherlands
Re: How do I synchronously execute commands?
Ok, thanks for the help!
The final script turned out as such:
There are only 2 problems left:
1.
XyPlorer's GUI didn't react anymore while the script was running.
How can I solve this?
2.
How can I prevent the shells / command prompts / dos boxes from popping up? I.e., I want the shells to start minimized so I don't lose the focus 100 times.
The final script turned out as such:
Code: Select all
$SelFiles = get("SelectedItemsPathNames", "|");
foreach($file, $SelFiles)
{
$file = quote($file);
run "E:\Utilities\XnView\AddOn\PngOut.exe" $file, , 1
}1.
XyPlorer's GUI didn't react anymore while the script was running.
How can I solve this?
2.
How can I prevent the shells / command prompts / dos boxes from popping up? I.e., I want the shells to start minimized so I don't lose the focus 100 times.
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: How do I synchronously execute commands?
Then better go the highend way and out-source the work to an DOS batch:iycgtptyarvg wrote: 1.
XyPlorer's GUI didn't react anymore while the script was running.
How can I solve this?
Code: Select all
////// Wrap selected file names into an DOS command each, write that to an temp CMD file and execute it
////// Modify the 'user settings' to your own needs, select your files and execute this script
////// User settings:
$shell = "start /wait /min"; // read syntax in a DOS-Box with command> start /?
$app = quote("X:\path to\app.exe");
$paraBefore = "";
$Files = get("SelectedItemsPathNames", "|");
$paraAfter = "";
////// For Each File In FileS Do: add an line to an array, build from all parameters
////// initialize the $array var, and write the header of an batch file:
$array="@ECHO OFF<crlf>";
foreach($file, $Files){
$file = quote($file);
$array = $array . "$shell $app $paraBefore $file $paraAfter<crlf>";
}
////// Test output:
//text $array;
////// Write this to an temporary batch file:
$tempfile = "%temp%\xybatch<date yymmdd>.cmd";
writefile($tempfile, $array);
////// control it:
text readfile($tempfile);
////// prompt the user to execute or cancel:
msg "Continue? Really execute the batch?",1;
///if [OK] clicked, do it:
run quote($tempfile);
- - -
tryiycgtptyarvg wrote: run "E:\Utilities\XnView\AddOn\PngOut.exe" $file, , 1
2.
How can I prevent the shells / command prompts / dos boxes from popping up?
I.e., I want the shells to start minimized so I don't lose the focus 100 times.
run cmd /c "E:\Utilities\XnView\AddOn\PngOut.exe" $file, , 1
- - -
EDIT:
because of <post below> and putting the in quotes for the run() command.
EDIT2:
'Than' should be 'Then'
Last edited by Stefan on 16 Jul 2011 20:34, edited 2 times in total.
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: How do I synchronously execute commands?
In the way that a foreach loop could start the first openwith, wait till it's finished, enter the second loop, start the second openwith etc.? And that all in a background mode where XYplorer is usable while the script is running? At least that would be a long anticipated featureSeams to me the openwith() as command and also in UDC missed an Wait=1 parameter.
Maybe this could be an improvement wish to Donald:
openwith application, [mode (s|m|W)], [item]
where 'w' is the same as 'm' but will wait till the called process has finished the task right before.
One of my scripts helped you out? Please donate via Paypal
-
Sander Bouwhuis
- Posts: 249
- Joined: 10 Jun 2008 15:40
- Location: Netherlands
Re: How do I synchronously execute commands?
Wow Stefan, you are awesome!
I ended up with this:
For some strange reason, I cannot use the run "$tempfile"; command when there are spaces in the $tempfile name; that is why I used underscores. Is there anything I did wrong?
I ended up with this:
Code: Select all
$array="";
$Files = get("SelectedItemsPathNames", "|");
foreach($file, $Files)
{
$file = quote($file);
$array = $array . "start ""PngOut"" /wait /min /low ""E:\Utilities\XnView\AddOn\PngOut.exe"" $file<crlf>";
}
$tempfile = "E:\Temp\PngOutBatch_<date yyyy-mm-dd_hh-nn-ss>.bat";
writefile($tempfile, $array);
run "$tempfile";(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: How do I synchronously execute commands?
As always, if there are spaces in path or file name, you have to put the whole string into quotes.iycgtptyarvg wrote: For some strange reason, I cannot use the run "$tempfile"; command when there are spaces in the $tempfile name; that is why I used underscores. Is there anything I did wrong?
-
I wanted to do this too, but i had problems, i always get an error message:
"Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch."
Because i used this quoted path for writefile() and readfile() which both not understood to handle this (as far as i understand)
Wrong code:
Code: Select all
$array ="@ECHO OFF & echo hello iycgtptyarvg &PAUSE";
$tempfile = quote("%temp%\xybatch<date yymmdd>.cmd)";
writefile($tempfile, $array);
text readfile($tempfile);
run $tempfile;But the run() command launches the shell execute which needs quotes around path with spaces.
So the trick is to quote the path only for the run() but not for the writefile() and readfile() command:
Working code:
Code: Select all
$array ="@ECHO OFF & echo hello iycgtptyarvg &PAUSE";
$tempfile = "%temp%\xybatch <date yymmdd>.cmd";
writefile($tempfile, $array);
text readfile($tempfile);
run quote($tempfile);
-
Sander Bouwhuis
- Posts: 249
- Joined: 10 Jun 2008 15:40
- Location: Netherlands
Re: How do I synchronously execute commands?
Hmmm... this scripting stuff is quite confusing.
I can't thank you enough for this. Because of you, I'm now able to use this script for similar situations.
Thank you, thank you, thank you!
I can't thank you enough for this. Because of you, I'm now able to use this script for similar situations.
Thank you, thank you, thank you!
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
XYplorer Beta Club