Multiple shell instances

Hi,
How to run multiple shell instances from the same app in xojo
Thank you

Declare multiple shell objects and keep a reference to each. Use the reference to send commands to the shell.

1 Like

You’ll also need to be sure to run the shells in asynchronous mode

1 Like

Thank you for your reply, but i don’t know the number of shells to be created beforehand, i want to create a shell whenever its needed during execution (e.g : button is pressed or a task is required).
also ,one more thing, what if i might need only one, why to allocate the resources for 4 shells.

Thank you for your reply,
i already tried to use async, this is my code in the button pressed event handler

var params as string
var command as string


sh = New Shell
sh.ExecuteMode = Shell.ExecuteModes.Asynchronous

AddHandler sh.dataavailable, addressOF PrintAvailableData
AddHandler sh.completed, AddressOf ShellCompleted

comman = "command to be executed"


sh.Execute(command)

with only one shell running whenever i try to run another shell (i press the button) the running shell is being terminated and the new shell starts executing
the shell is a property of the window

Instead of just sh = New Shell where sh is a property, create an array instead

shells() as Shell

Then you can do

Var sh as New Shell
shells.Add sh

// The rest of your code

That way your aren’t overwriting your single shell each time

1 Like

You don’t have to know before hand. You can create a new shell using “New Shell”.

However, you must keep a reference to the shell or it will be destroyed. If you keep the reference in a local variable then the shell will disappear when the method ends. If you keep it in a property it stays until the object is closed, however, if you overwrite that same property with another shell the first one will be destroyed.

You could have an array of shells as a property of the App. Then the shells will continue for the duration of the app.

Var oShell as New Shell
App.MyShells.Add New oShell // This will keep the Shell alive.

However, you will need something to close them when you are done with them.

1 Like

Thank you for your help, it worked :slight_smile:

Thank you for your reply , your help is much appreciated , it worked :smile: