Script to call an .exe with parameters

Welcome Forums General PowerShell Q&A Script to call an .exe with parameters

Viewing 3 reply threads
  • Author
    Posts
    • #267740
      Participant
      Topics: 1
      Replies: 1
      Points: -5
      Rank: Member

      Hi All,

      I’m new to both Poweshell and Imgaemagick so please bare with me.

      My task is to monitor a folder for new file creation of .jpeg and .jpg.

      After file is created copy file to backup folder and then call Imagemagick to resize original file.

      How do I call imagemagick and send parameters?

      From the command line Imagemagick works as follows

      magick convert rose.jpg -resize 50% new_rose.jpg

      • This topic was modified 1 month ago by grokkit. Reason: code formatting - please read the guide
    • #267785
      Participant
      Topics: 9
      Replies: 677
      Points: 2,680
      Helping Hand
      Rank: Community Hero

      I would simplify this a few different ways and also move the definition of the backup path and image magick executable to ensure it’s defined in the scriptblock. I’ve tested this and it works perfectly.

    • #267797
      Participant
      Topics: 0
      Replies: 6
      Points: 31
      Rank: Member

      Hi Mcaston15,

      Several ways to go about it it seems. You could use the Start-Process cmdlet:

      Start-Process -FilePath “C:\Program Files\ImageMagick-7.0.10-Q16-HDRI\magick.exe” -ArgumentList “convert rose.jpg -resize 50% new_rose.jpg”

      Or why not using the call operator (&):

      & “C:\Program Files\ImageMagick-7.0.10-Q16-HDRI\magick.exe” convert rose.jpg -resize 50% new_rose.jpg

      Check this link for more details on how to run executables in Powershell:

      https://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx

    • #268715
      Participant
      Topics: 1
      Replies: 1
      Points: -5
      Rank: Member

      Hi Doug,

      Thanks for your help.  That worked.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.