start other programs within xojo

Hi,

among other things i want to use xojo to start other programs.

Until now i’m using visualbasic for this task.

3 Problems occured to me when trying to do this:

  1. I want to start a program.
    So in Visulabasic i do:
    prg$=“C:\Program Files (x86)\OpenOffice 4\program\swriter”
    blah = Shell(prg$, 1)
    -> Openoffice Writer starts

    in xojo i do:
    f=gettruefolderitem(“C:\Program Files (x86)\OpenOffice 4\program\swriter”)
    if f.Exists then
    f.Launch
    else
    msgbox “not found.”
    end
    -> xojo tells me ‘not found’

    i have to do:
    f=gettruefolderitem(“C:\Program Files (x86)\OpenOffice 4\program\swriter.EXE”)
    -> Openoffice Writer starts

    Indeed that’s not a real big problem, i’m curious why it’s like that.

  2. I want to start a programm and pass a argument to the program.
    So in Visulabasic i do:
    prg$=“C:\Program Files\XnViewMP\xnviewmp.exe c:\pictures”
    -> my pictureviewer starts and show me the path wich i included in the commandline.

    in xojo i do:
    f=gettruefolderitem(“C:\Program Files\XnViewMP\xnviewmp.exe c:\pictures”)
    if f <> nil then
    if f.Exists then
    f.Launch
    else
    msgbox “not found.”
    end
    end if
    -> xojo does nothing

    How can i pass arguments to my programs?

  3. I want to start a program and let it run as if i started it in it’s directory.
    i.e. start a shellscript that uses a program wich is stored in that directory.
    In the script the command ‘rsync.exe’ wich is stored in ‘c:\scripts’ is called.

    In visualbasic i do:
    prg$=“C:\scripts\script.bat”
    blah = Shell(prg$, 1)
    -> script starts, and executes rsync.exe

    if i do the same in xojo:
    my script tells me: ‘rsync.exe’ not found.

    So it seems xojo don’t switch to the path of the command.
    How can i accomplish that (switch to the path of the called programm/batch etc.)?

I hope that’s not too many questions for 1 post.

Regards

Solved.

post your solution for others that come across this topic please
this creates a learning experience not only for you, but for others as well

I agree that at least linking to where you found the solution helps others

There are two ways to do what you want.

  1. Shell. You must use full valid paths. That accounts for the “.exe”.

  2. Launch. You have not read the LR correctly. You are trying to start the program and the argument in the same line. The proper way is :

getFolderItem(C:\\Program Files\\XnViewMP\\xnviewmp.exe, FolderItem.PathTypeShell).Launch(" c:\\pictures")

Note that I did not use an extra FolderItem variable, GetFolderItem creates one on the fly. It is also a good habit to always indicate the kind of path used. On Windows, you can get away without, but on Mac or Linux, it will not work.

For the batch, see https://forum.xojo.com/31960-shell-openup-path/0

Hi,

eventually i decided to go with the shell.

I don’t tried Michels way with the launch-method, but i believe that there may
still be the path-problem (see my point 3.)

-> ‘start a program and let it run as if i started it in it’s directory.’

i did

mShell = New shell
mShell.Mode = 2
cmd = “c: && cd \Program Files (x86)\OpenOffice 4\program\ && scalc.exe c:\docs\example.ods”
mshell.Execute cmd

Send several shell-commands in one line, separated by ‘&&’.
That did the trick.

Regards