It is currently Sun Jul 21, 2024 10:27 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Custom Command with arguments and status return
PostPosted: Mon Feb 10, 2014 7:17 am  (#1) 
Offline
GimpChat Member

Joined: Feb 08, 2014
Posts: 26
Hi, I am trying to make a custom command take some arguments and return a (status) value. Everything works when I don't request the status value, when I do an error appears.

The custom command (custom.gmic):
#@gmic customadd : '"param1","param2"' : test1
customadd :
-status {$1+$2}
-return


This works:
gmic -m custom.gmic -customadd 1,2


Terminal:
[john@asusarch Desktop]$ gmic -m custom.gmic -customadd 1,2
[gmic]-0./ Start G'MIC parser.
[gmic]-0./ Import custom commands from file 'custom.gmic' (added 1 command, total 1478).
[gmic]-0./customadd/ Set status to '3'.
[gmic]-0./ End G'MIC parser.


This fails:
gmic -m custom.gmic -echo @{-customadd 1,2}


Terminal:
[john@asusarch Desktop]$ gmic -m custom.gmic -echo @{-customadd 1,2}
[gmic]-0./ Start G'MIC parser.
[gmic]-0./ Import custom commands from file 'custom.gmic' (added 1 command, total 1478).
[gmic]-0./ @{-customadd
[gmic]-0./ Input file '1' at position [0]
[gmic]-0./ *** Error in ./ *** Unknown filename '1,2}'.
[gmic]-0./ Abort G'MIC instance.

[gmic] *** Error in ./ *** Unknown filename '1,2}'.


any ideas?


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Custom Command with arguments and status return
PostPosted: Mon Feb 10, 2014 8:37 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
Hi Johniak,
Remember that the ' ' (space) character is an item delimiter, so in your case the @{-customadd 1,2} will be separated as two different items '@{-customadd' and '1,2}'.
That's why you have the message :
[gmic] *** Error in ./ *** Unknown filename '1,2}'.

The solution is to add quotes around. But, the difficulty when you start to deal with spaces, and quotes and things like this, is that the bash does its own substitution, so when calling gmic from the command line, you need to take care of all these possible substitution, and it can become very hard to make it working.
In your case, the best solution would be to write your function into a command file, to test it :
foo :
  -echo @{-customadd" "1,2}   # Just added double quotes around the spaces to make it as a single item.

then,
$ gmic custom.gmic -foo

should work. It is recommended to test this kind of 'complex' stuffs in a custom function instead of trying to write it directly in a shell, to avoid headaches :)


Top
 Post subject: Re: Custom Command with arguments and status return
PostPosted: Tue Feb 11, 2014 5:54 am  (#3) 
Offline
GimpChat Member

Joined: Feb 08, 2014
Posts: 26
Thanks a lot! It worked!

Just for completeness, if anyone needs it...

Custom Command (custom.gmic)
#@gmic customadd : '"param1","param2"' : test1
customadd :
-status {$1+$2}
-return

#@gmic foo : : test1
foo :
-echo @{-customadd" "1,2}


and the Terminal:
[john@asusarch Desktop]$ gmic -m custom.gmic -foo
[gmic]-0./ Start G'MIC parser.
[gmic]-0./ Import custom commands from file 'custom.gmic' (added 2 commands, total 1479).
[gmic]-0./foo/*substitute/customadd/ Set status to '3'.
[gmic]-0./foo/ 3
[gmic]-0./ End G'MIC parser.
[john@asusarch Desktop]$


Top
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Invalid parameter name dialog status error

4

No new posts The return of the Lord of The Rings script for Gimp 2.10

0

No new posts Attachment(s) Return of Psychedelic Text and Alpha (Rel 4), for Gimp 2.10 only

5

No new posts Attachment(s) Font In Status Bar Not Loading Correctly (on top of other font issues)

4

No new posts Attachment(s) HELP - SEARCH AND RUN A COMMAND

6



* Login  



Powered by phpBB3 © phpBB Group