Calling Compiled Projects

I’m a relative beginner. I have 15-20 small compiled projects that I would like to call from a master project as if they were subroutines. Looking through the documentation, I tried search words like call, executable, resources, etc, but didn’t really find anything. Can anyone tell me where to locate the precompiled projects and what is the proper syntax for calling them? Thanks in advance.

Create a Shell object and then call the Execute method.

Thanks for the reply, Greg. I tried this…

dim s as shell
dim info as string

s = new shell
if s.ErrorCode = 0 Then
info = s.Result
msgbox info
msgbox("Error code: " + str(s.ErrorCode))
end If

…and got Error 1 no matter where I put the test files. Might Error 1 be file not found? I’m on a Mac, and the test files are compiled under Xojo.

You need to use the full path to the executables.

Are the apps console apps? You can use a simple folderitem.launch to open other apps. You can use AppleScript for communication or some type of socket.

Thanks, Beatrix. That fixed Error 1. Now I get Error 127. Can you point me toward the right error codes?

Don’t think the apps are console apps, at least not if the/an alternative to console is desktop. If you’re saying that I can call console apps with folder item.launch, might not the best approach be to recompile or rewrite the apps as console apps? Thanks again.

The docs say that everything except 0 is system supplied. But there is no system error 127.

It really depends on what you want to do. My own main app has

  • a Python helper app which needs the shell to communicate
  • a Mac helper app without interface that is using a simple AppleEvent
  • another helper app with interface that uses sockets to communicate
  • and another helper app that is called by registering an url (for a bug in Evernote)

as far as I know, error 127 is “command not found”

try this

dim f as folderitem = get_path_to_executable

dim com_line as string = " --param1=xxx --param2=xxx"

#if targetWindows
f.launch com_line
#elseif targetMacOS
dim s as new shell

s.execute f.shellpath+" “+com_line+” >/dev/null 2>&1 &"

Beatrix: As a beginner, I’m not smart enough to know what I want to do, other than call a precompiled app and have a value returned. Might be best to think of me as a QuickBasic user who’s having trouble getting with the OOP.

Connor: Thanks for the code. Guessing I have to specify a file path somewhere; would that be inside the quotes in the dim com_line statement?

For mac, its specified in f.shellpath
for windows, you can use folderitem.launch to invoke the exe, if you require a result from the child processes, you can simple use:

dim f as folderitem = get_path_to_executable
dim com_line as string = " --param1=xxx --param2=xxx"

dim s as new shell
s.execute f.shellpath+" "+com_line

This line

dim f as folderitem = get_path_to_executable

causes the error message “this item does not exist.” So I don’t know if it works. Also, assuming I want to pass params, do I put them where the xxx is? Further thanks.

you must replace get_path_to_executable
with something like

Dim f As FolderItem f = New FolderItem("/home/shr/mytextdoc.txt",FolderItem.PathTypeShell)
and specify where is the executable you want to launch

The com_line is a string that you can pass as an addition to an app (its optional). it allows you to make your app behave differently if you want.

//assume the parameter is " --mode=utility"

dim s as string = System.CommandLine
for each part as string in s.split(" ")
if part = “–mode=utility” then
//set the application to utility mode
end if

One perk of this is you can have your main application invoke itself with a certain parameter, and have it process something, replicating a thread. (removing the need for many different smaller apps)

Think I can make it work now. I’ll come back after intensive trial-and-error with either success or more whining. Much appreciation to everyone.