How to launch an external program

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
jerome
Posts: 2
Joined: Thu Jul 17, 2008 7:23 pm

How to launch an external program

Post by jerome »

Hello,

In VBA, I used the following code in order to launch an external program:
----
cmd = q & VBA.Environ("SystemRoot") & "\system32\cmd.exe" & q & " /c " & drive & " && cd " & q & procPath & q & " && launch.bat"
VBA.Shell cmd, vbHide
----

I could not find how to do the same with OOBasic.

Thanks for your help.
User avatar
squenson
Volunteer
Posts: 1885
Joined: Wed Jan 30, 2008 9:21 pm
Location: Lausanne, Switzerland

Re: how to launch an external program

Post by squenson »

From the excellent A. Pitonyak's e-book (section 5.33), I manage to launch any program:

Code: Select all

  Dim oSvc as object
  oSvc = createUnoService("com.sun.star.system.SystemShellExecute")

  Rem Launch notepad
  oSvc.execute(ConvertToUrl("C:\windows\notepad.exe"), "", 0)
LibreOffice 4.2.3.3. on Ubuntu 14.04
arfgh
Posts: 570
Joined: Tue Mar 05, 2013 6:44 pm

Re: how to launch an external program

Post by arfgh »

question, and very interesting...

if we run for example the '7za' (7-zip cmd program) command-line program, can we also capture its exit ?
the end is the DB file integrity check.

Highly interesting in my opinion ....
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Zizi64
Volunteer
Posts: 11419
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: how to launch an external program

Post by Zizi64 »

if we run for example the '7za' (7-zip cmd program) command-line program, can we also capture its exit ?
Just a foggy idea:
If you can parametrize the launching command of the software to launch, then you can control the place: where to unpack the file/s/.
And then you can load the extracted file from the known URL by the "LoadComponentFromURL()" API function (as a return value of the function) into an Object type variable.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
arfgh
Posts: 570
Joined: Tue Mar 05, 2013 6:44 pm

Re: how to launch an external program

Post by arfgh »

example of use of that ?
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Zizi64
Volunteer
Posts: 11419
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: how to launch an external program

Post by Zizi64 »

example of use of that ?
I do not know anything about the parameters of the launch command of the '7za' (7-zip cmd program) command-line program. I suppose that you need pass two parameters: the URL of the file to unpack, and the URL or path of the target file/directory.


About the LoadComponentFromURL(): There are many examples in this forum. Search them.
viewtopic.php?f=20&t=57390
https://wiki.openoffice.org/wiki/Docume ... tarDesktop
http://ooo-forums.apache.org/en/forum/v ... 20&t=38778
...etc...
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Jurassic Pork
Posts: 26
Joined: Wed Oct 25, 2017 7:55 am
Location: France

Re: how to launch an external program

Post by Jurassic Pork »

hello,
with the extension EasyDev (see here) it's easy :) :
to compress some files and see the crc :

Code: Select all

REM  *****  BASIC  *****
Sub Tst_7za()
util = createUnoService("org.universolibre.EasyDev")
res = util.execute(Array("cmd.exe","/c","F:\7zip\7za.exe",_
      "a","F:\temp\Files.7z","F:\temp\*.txt"), True)
util.msgbox(res)
res = util.execute(Array("cmd.exe","/c","F:\7zip\7za.exe",_
      "h","F:\temp\Files.7z"), True)
util.msgbox(res)
End Sub
tst-7za-1.png
tst-7za-2.png

Friendly, J.P
OpenOffice 4.1.14 , LibreOffice 7.6.2.1 on Windows 11/ LibreOffice 7.3.7 on Lubuntu 22.04
arfgh
Posts: 570
Joined: Tue Mar 05, 2013 6:44 pm

Re: how to launch an external program

Post by arfgh »

well, the end was just to check the own .odb document integrity... and yes you are using an extenion, exist no way to do it without another extension ?
Anyways, what's the purpose of EasyDev ?
Last edited by arfgh on Sat Nov 04, 2017 2:05 am, edited 1 time in total.
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Jurassic Pork
Posts: 26
Joined: Wed Oct 25, 2017 7:55 am
Location: France

Re: how to launch an external program

Post by Jurassic Pork »

certainly but it will be more complicated or use a python macro
OpenOffice 4.1.14 , LibreOffice 7.6.2.1 on Windows 11/ LibreOffice 7.3.7 on Lubuntu 22.04
arfgh
Posts: 570
Joined: Tue Mar 05, 2013 6:44 pm

Re: how to launch an external program

Post by arfgh »

i see that you used the 'special msgbox' from EasyDev to show the results.
Exist that documentation in pdf ?
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
Post Reply