[Dropped] Problem executing mogrify command

Talk about anything at all....
Post Reply
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

[Dropped] Problem executing mogrify command

Post by phasel »

Hello,
I am trying to execute a shell command from a macro. I have some macros that copy files to folder and they work.
For example:
smove = "bash -c ""cp " & sficheropath & "/" & sfichero & " " & spathfinal & """"
shell(smove)
works, but now I am trying to reduce file size:
sscript = "bash -c ""mogrify -strip -interlace Plane -quality 85% & sficheropath & "/" & fichero & """"
shell(sscript)

This does not work. I have tried with shell() command, with ' quotes instead of " after bash -c...
I have even tried to populate a file with echo and then execute, but the echo "" > does not work either.

Nothing works and Script executed from terminal works.

Any idea?
Thanks a lot for your help,

Best regards,

Rodolfo
Last edited by MrProgrammer on Sat Jun 17, 2023 3:47 pm, edited 2 times in total.
Reason: Dropped: "in standby until I can test new version"
OpenOffice 4.1.14 MacOSX
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Problem executing shell command

Post by JeJe »

I presume you've looked at the old threads on this like this one:

viewtopic.php?t=19427

Does it work in a bash script? I don't have a Mac so can only make a wild suggestion... if the answer is it just won't work from OO Basic would it be possible to write a bash script file from within Basic, make it executable and run it?

Edit: Or just create the script file outwith OO but run it from OO?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

Re: Problem executing shell command

Post by phasel »

Hello,
Thanks for answering.
Yes I checked old threads. Actually the one you mention shows the same problem in the last two unsolved messages. Script works from shell directly when I execute directly or from file. From macro, Simple cp, mv or rm actually work with the double quotes, but executing mogrify or the .sh file do not work.
I am out of ideas.
Thanks a lot for your help,

Best regards,

Rodolfo
OpenOffice 4.1.14 MacOSX
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

Re: Problem executing shell command

Post by phasel »

Hello,
Actually I played a little bit with the script, and it runs it. I cannot write to a file, but if I put in the script operations like creating a folder, those actually work. So, a bash file that can be executed from terminal, with only a folder creation plus the mogrify command (imagemagick), only creates the folder when executed from the macro. I don't really get it.
Thanks a lot for your help,

Best regards,

Rodolfo
OpenOffice 4.1.14 MacOSX
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

Re: Problem executing shell command

Post by phasel »

Hello,
Yes, my mistake with the pasting here. I have been doing several trials and copied a works in progress.
Anyway, the latest variation I am trying. I get the variables from a database, so I execute the macro from a button in a base form.
I have changed from reduction in size to rotate the image, so it is more clearly visible.
sficheropath is defined at the beginning, as the folders where images are stored. scategoria is read from the database for the entry, and the same with scat which is the number of the image in that category. All of that works, and the MsgBox gives the right bash -c that I can execute from bash directly.

This is the important part of the macro:

sficheropath = sficheropath & scategoria & ""

smoverim = "bash -c ""mogrify -rotate 20 -trim " & sficheropath & "/" & scategoria & "-" & scat & ".jpg"""
MsgBox(smoverim)
shell(smoverim)
'shell("bash -c ""/Users/rodolfo/run.sh""")
verimagenes(oEv)
MsgBox("finalizado")

verimagenes is another macro to show the image in a box, so I can see if it has rotated 20 degrees clockwise.
Rotating takes a few seconds, and from the first MsgBox to the second one, there is no time to run the mogrify script.
Actually, in the run.sh file that I also tried, I included a folder creation + the mogrify. The folder is created but image is not rotated. My best guess is that OO kills the script before it has time to finish. Would there be a way to test this?, if that is the case, anyway to keep the shell alive?
Thanks a lot for your help,

Best regards,

Rodolfo
OpenOffice 4.1.14 MacOSX
User avatar
Lupp
Volunteer
Posts: 3553
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Problem executing shell command

Post by Lupp »

I never used a Mac, but from my poor basical understanding of OS-terminals I would suspect:
The terminal isn't a command interpreter in itself. It's a part of the UI of the OS. Thus it may depend on settings made at any point of the process of installation and configuration of the OS (Do you want to install imagemagick? e.g.) Probably it's the terminal that first parses the command and decides to prefix a call to imagemagick if a first token "mogrify" is found.
A SHELL or BASH call may skip the terminal level and directly go to a command interpreter knowing how to call imagemagick, but not understanding mogrify.
Is there a way to explicitly call imagemagick from the shell, and to pass the "mogrify" subcommand and its options/parameters behind? If so, I wouild try that way.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

Re: Problem executing shell command

Post by phasel »

Hello,
Thanks for answering. I would like to try from ubuntu if I have time one of these days... to check if this macro works or it does not.
I have tested the shell, and mogrify or convert commands do work directly from bash, or if I execute it with bash -c from shell it work too. It is weird.
I also left the true as an option (if I understand correctly, it should leave the command finish), without success, also finishing the command with &... same result.
Thanks a lot for your help,

Best regards,

Rodolfo
OpenOffice 4.1.14 MacOSX
User avatar
MrProgrammer
Moderator
Posts: 4909
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Problem executing shell command

Post by MrProgrammer »

Proof of concept: Generate QR code in Calc is an example of using SHELL from Basic.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

Re: Problem executing shell command

Post by phasel »

Hello,
Thanks for the example. It works, so simple commands I have tested works, and qrencode also works. There must be an issue with running mogrify or convert commands, even though they do work from bash.
Has anyone run them from other OS?
Thanks a lot for your help,
Best regards,

Rodolfo
OpenOffice 4.1.14 MacOSX
User avatar
RoryOF
Moderator
Posts: 34619
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Problem executing shell command

Post by RoryOF »

Creep up on it; make a simple bash script to get (for example) mogrify running, then add each extra application one by one.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

Re: Problem executing mogrify command

Post by phasel »

Hello,

Not able to get mogrify to run at all. I checked imagemagick, and there is a newer version where they have changed how the command line works. I wanted to test, but as I do not have latest OS version, I am not being able to compile. I will check again when I am willing to update OS.
Thanks a lot and best regards,

Rodolfo
OpenOffice 4.1.14 MacOSX
User avatar
RoryOF
Moderator
Posts: 34619
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Problem executing mogrify command

Post by RoryOF »

Almost all the examples I find are in form
magick mogrify [parameters]

See, for example (there are other sites as well)
https://imagemagick.org/script/mogrify.php
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

Re: Problem executing mogrify command

Post by phasel »

Hello,

Yes, that's the thing, last version has changed the call of the commands, so I wanted to check last version, but I am being unable to install some dependencies due to having an old version of OS.
I will check again when I am willing to install the new OS version.
Thanks a lot and best regards,

Rodolfo
OpenOffice 4.1.14 MacOSX
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Problem executing mogrify command

Post by Villeroy »

Forget Basic, forget all macro programming.
https://ask.libreoffice.org/t/calc-how- ... le/89059/9
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

Re: Problem executing mogrify command

Post by phasel »

Thanks for the comment. Interesting, but I wanted to work from a form. It is a product database and I can see the picture in the form. Pictures are often not well done, they need rotation, and reduction, and I want to quickly do it when I see the product in the database.
Of course I can take the picture name from database, go to the command line and do it, then go back to refresh but... it takes a lot longer.
Thanks anyway, all interesting uses.
Best regards,

Rodolfo
OpenOffice 4.1.14 MacOSX
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

Re: Problem executing mogrify command

Post by phasel »

Yes indeed! There are thousands of products… this is an investment! XD
I will leave it in standby until I can test new version.
Thanks anyway!
Best regards
OpenOffice 4.1.14 MacOSX
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Problem executing mogrify command

Post by Villeroy »

Just in case...
Do NOT store any pictures in an embedded database. Sooner or later it will crash on you and the embedded database will be lost. Store pictures as picture names in a text field and let the form's picture control refer to the text field. It will display the pictures while you can do with the files whatever necessary.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

Re: Problem executing mogrify command

Post by phasel »

Hello,
Yes, That is what I do. Name is stored in database, and pictures are in a folder in subfolders separated by category (and then name is category + number in database + extension, almost always jpg). I do not like to have any object in database. I call the pictures with a macro.
Best regards!
OpenOffice 4.1.14 MacOSX
Mountaineer
Posts: 318
Joined: Sun Sep 06, 2020 8:27 am

Re: Problem executing mogrify command

Post by Mountaineer »

Especially on Mac check stackoverflow:
https://stackoverflow.com/questions/756 ... solve-this

So you might need the full path to your command.

If you update to v7 note also the new prefix magick instead of using mogrify directly as a command.
OpenOffice 3.1 on Windows Vista
phasel
Posts: 13
Joined: Sat Apr 29, 2023 7:04 pm

Re: Problem executing mogrify command

Post by phasel »

Thanks for the hint. I tested it and unfortunately, it is not that :(
I will check v7 when I can. I hope that solves the issue...
Thanks a lot and best regards,

Rodolfo
OpenOffice 4.1.14 MacOSX
Post Reply