Exec & Shell
Posted
#1
(In Topic #717)
Expert

I'm trying to run an Open office command line instruction using Exec or Shell.
It's not working, but if I run exactly the same command from the terminal, it works as required.
The process uses 'soffice' to convert a writer document (.odt) file to a txt file.
Terminal command:
soffice –headless –convert-to txt "{path}/myfile.odt"
The quote characters are required as the path has a comma in it - not ideal, but it is what it is.
Again, this works from the command line but not from Gambas.
Any thoughts would be appreciated.
I've also use to "To" parameter to see if there is a resultant error message, but in both cases it returns nothing.
Useful fact: You can use the same command with html instead of txt to convert a odt document to html.
Cheers - Quin.
I code therefore I am
I code therefore I am
Posted
Guru

I start my progs with …
I find this has fixed many a glitch.
Also what's with Chr(34) ?
Will this not work ?
Or…
hmm what's that {path} ? should that not be some gambas code providing an actual path?
did you try ..
just to check the command line looks right, valid paths n all?
Posted
Guru

The following works to change an .odt file with a silly name into a text file: -
The changing of the folder at the beginning of the Shell command will create the new file in the same folder, you can remove it if you are happy for the file to be created in your Home folder.
I suggest your code checks that you have created the new file and if not pops up a warning to close LibreOffice (OpenOffice) as you can't do this conversion if LibreOffice (OpenOffice) is open
<IMG src="https://www.cogier.com/gambas/LOConvert.png">
</IMG>
Posted
Guru

If {path} is an Env variable the shell is looking for you can supply it with "With"
This could be one way to do it..
Or something like that
Posted
Guru

shell must have $ char to access variables
Prints…
this is {path}
this is hello there
Doing functions on strings in bash is the only time i use {} for just the path text you'd use $path using ${path} makes sense when perfoming action like mid string functions like ${path##*/}
Like this ..(gets path part and filename part)…
this is /my/path/to/file.txt
this is /my/path/to
this is file.txt
thought it worth a mention
Posted
Expert

@ Bruce - The Gambas Quote function has failed on every SQL statement I've used it on so far, so my confidence is somewhat lacking.
I'll have another look to cover all bases, but I'm not confident.
I found this: libreoffice is a shell script that sets up the environment and passes the command line arguments to the soffice.bin binary. Here
So I might play around with using the command libreoffice instead of soffice.
Also, you can do multiple files at the same time by using libreoffice –headless –convert-to txt {path}/*.odt
This will run the conversion process against all .odt files in the target folder.
Gut feel is that the folder and file name both having a apostrophe in them is the causing the failure. Lesson learnt about doing that again !.
Cheers - Quin.
I code therefore I am
I code therefore I am
1 guest and 0 members have just viewed this.


