0

I am trying to run an imagemagick command line in my windows powershell but it does not work, if I run it in my regular command line it does work.

The command looks like this:

(I do not need the linebreaks, I just put them so that the command is more readable)

convert -bordercolor none -background none -gravity center ^
k1.jpg -border 5x5 ^
( k2.jpg k3.jpg k4.jpg -border 5x5 +append ) ^
( k5.jpg k6.jpg k1.jpg -border 5x5 +append ) ^
-append -border 5x5 -resize 720x480 output.png

I get following error if I run it in my powershell: ( I had to translate it into english)

k2.jpg : the wording "k2.jpg" was not detected as a name of a cmdlet, a function, a script file.

Edit:

Actually I do not need the lines breaks, I just put them so that the code is more readable, if you have a suggestion without the line breakers it is fine aswell.

Edit:

I tried Matt's suggestion like this:

convert --% -bordercolor none -background none -gravity center k1.jpg -border 5x5 (k2.jpg k3.jpg k4.jpg -border 5x5 +append) (k5.jpg k6.jpg k7.jpg -border 5x5 +append) -append -border 5x5 -resize 720x480 output.png

And I got following error/message:

convert.exe: unable to open image '(k2.jpg': No such file or directory @ error/blob.c/OpenBlob/2695. convert.exe: unrecognized option `+append)' @ error/convert.c/ConvertImageCommand/764.

utdev
  • 3,942
  • 8
  • 40
  • 70
  • Powershell uses other line-breaks: http://stackoverflow.com/questions/3235850/how-to-enter-a-multi-line-command – D.J. Sep 27 '16 at 14:41
  • @D.J. thank you I did not know that, I don't really need the line breaks in my command I just put them down so that the command is more readable. After trying your suggestion I get the same error above. – utdev Sep 27 '16 at 14:45
  • That second error is not from PowerShell anymore. That is coming from convert.exe. It would appear the stop parsing parameter is working as intended now. – Matt Sep 27 '16 at 15:39
  • Try adding either a circumflex (`^`) or a backslash, or a back-tick before both `(` and `)`. – Mark Setchell Sep 27 '16 at 19:52
  • @MarkSetchell thanks but it did not work – utdev Sep 28 '16 at 07:49
  • 2
    Oh, you **must** leave spaces **both** sides of `(` and `)`. – Mark Setchell Sep 28 '16 at 08:42
  • @MarkSetchell hmm could you post that command please – utdev Sep 28 '16 at 08:52
  • 2
    I don't want to tread on @Matt 's toes as he has done all the hard work, so I won't post an answer. All, I'm saying is that I noticed in your question, where you say you tried Matt's suggestion, the command you tried has not got spaces both sides of the parentheses and you MUST include those - exactly as you did with the first command you showed in your question. – Mark Setchell Sep 28 '16 at 08:57
  • Great that worked – utdev Sep 28 '16 at 09:12
  • 1
    @MarkSetchell Thanks for the assist. – Matt Sep 28 '16 at 09:47

1 Answers1

2

Main issue is that PowerShell is trying to treat those like PowerShell syntax. () denotes an expression.

There are multiple ways of handling exe's in PowerShell. Depending on your intention and PowerShell version some options are more of a pain then others (Some even deprecated by more preferred methods).

The easiest thing to do with what you have shown is to use the stop parsing operator:

The stop-parsing symbol (--%), introduced in Windows PowerShell 3.0, directs Windows PowerShell to refrain from interpreting input as Windows PowerShell commands or expressions.

So you could just do this instead:

convert --% -bordercolor none -background none -gravity center....

I don't have an environment to test what you are doing but perhaps you can use quotes around those arguments so PowerShell won't think of it as anything but a string.

"( k2.jpg k3.jpg k4.jpg -border 5x5 +append )"
Matt
  • 45,022
  • 8
  • 78
  • 119
  • Thank you for your suggestions, I tried your second suggestion first :) unfortunatly it did not work, do I need to call on your first suggestion --% just once at the start or do I need to call it more than once? – utdev Sep 27 '16 at 15:28
  • Once at the start @utdev – Matt Sep 27 '16 at 15:29
  • I tried your suggestion but it did not work I udpated my question with the command I used + error / message from the command line – utdev Sep 27 '16 at 15:34
  • I have to leave now, it may be too much to ask for but do you mind testing your command on your system if you can, so that I know that it is not a system error or something like that – utdev Sep 27 '16 at 15:41
  • @utdev From my answer _I don't have an environment to test what you are doing_ – Matt Sep 27 '16 at 15:43