Handing parameters to an external process with OsProcessStarter on Windows

93 views
Skip to first unread message

Joachim Tuchel

unread,
Aug 26, 2021, 11:32:34 AM8/26/21
to VAST Community Forum

Hi,

I am playing a little with OsProcessStarter and freinds to control external processes. I really like what I see so far. But I'm hitting a wall here that I don't really understand.
I'm trying to use ImageMagick on Windows. This commandline works fine in a cmd shell:

magick convert -density 150 -background white c:\tmp\input.pdf c:\tmp\output-%03d.jpg

Trying to do the same from VAST 10.0.2, I get an error message from imagemagick/convert on the error stream:

convert: unrecognized option `-density 150'' @ error/convert.c/ConvertImageCommand/1452.


So it seems like I am doing something wrong when constructing the command collection. This is my snippet to start the process:

        convertStarter := OsProcessStarter new.
            commandAndParams :=
                OrderedCollection
                    with: (System osType = 'Linux' ifTrue: ['magick'] ifFalse: ['magick.exe']).
            commandAndParams
                add: 'convert';
                add: '-density 150';
                add: '-quality 75';
                add: '-resize 60%';
                add: '-background white';
                add: '-alpha remove';
                add: '-alpha off';
                add: 'input.pdf';
                add: 'output-%03d.jpg'.


I also tried

add: '-density'; add: '150';

and so son, but that doesn't work either.

I am a bit helpless now. Why does entering the command in a cmd work with -density 150 but not in VAST? What do I have to do here?


Joachim





Seth Berman

unread,
Aug 26, 2021, 12:26:38 PM8/26/21
to VAST Community Forum
Hi Joachim,

This works
OsProcessStarter start: {
'C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\magick.exe'.
'convert'.
'-density'. '150'.
'-quality'. '75'.
'-resize'. '60%'.
'-background'. 'white'.
'-alpha'. 'remove'.
'-alpha'. 'off'.
'C:\Users\sberman\Desktop\sunflower.jpg'.
'C:\Users\sberman\Desktop\sunflower.png'.
}

This does not work: "convert: unrecognized option `-density 150'' @ error/convert.c/ConvertImageCommand/1452."
OsProcessStarter start: {
'C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\magick.exe'.
'convert'.
'-density 150'.
'-quality'. '75'.
'-resize'. '60%'.
'-background'. 'white'.
'-alpha'. 'remove'.
'-alpha'. 'off'.
'C:\Users\sberman\Desktop\sunflower.jpg'.
'C:\Users\sberman\Desktop\sunflower.png'.
}

Joachim Tuchel

unread,
Aug 27, 2021, 8:28:05 AM8/27/21
to VAST Community Forum
Hi Seth,

hmm. I thought I had tried that as well, but it turns out I haven't tried hard enough, obviously. Maybe I left an additional blank somewhere or had forgotten a dash when I tried.
The short story: your suggestion works.
I have to hand each part of the command line that is separated by a blank if entered in a cmd shell as its own element of the #command collection.

Thanks a lot.

Seth Berman

unread,
Aug 27, 2021, 9:04:49 AM8/27/21
to VAST Community Forum
Hi Joachim,

My pleasure. This is correct.  If you inspect the resulting OsVastSubprocess object, you can see the post-processed command in the inspector pane that was sent off to the exec() engines.
You can also send the subprocess object the message #commandLine and you will get the same information.

From this we can see that in the version that didn't work, it's because '-density 150' was quoted.
So the command line ended up being something more like:
'"C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\magick.exe" convert "-density 150" -quality 75 -resize 60% -background white -alpha remove -alpha off C:\Users\sberman\Desktop\sunflower.jpg C:\Users\sberman\Desktop\sunflower.png'

- Seth

Reply all
Reply to author
Forward
0 new messages