Asynchronous shell problem

I’m trying to run an asynchronous shell command like

Using Xojo.Core
Dim StartTime As Date
Dim Name As String

StartTime = Date.Now
Name = Name.ReplaceAll(":", "-")
Name = Name.ReplaceAll(" ", "_")
Name = Name + ".mp4"

Dim s As Shell
s = New Shell
s.Mode = 1

s.Execute("a very long ffmpeg command that creates a video named with the variable name")

It works when mode=0

In Windows it works in both modes

Any ideas?

You need to declare the shell property outside of the method. The way you’ve written this, the property goes out of scope at the end of the method and may be destroyed.

To fix, get rid of the Dim s as Shell line and instead make a property on the containing object (window, class, module, etc) to make sure it’ll stick around.

Thanks Greg
It took 4 minutes to get not only a solution but also an explanation. THIS FORUM ROCKS!!!

This is what i ended up doing

I added a property named “RenderShell” to my main window and in the opening event of the window i added:

Me.RenderShell = New Shell

Now my code looks like this and it works on Mac and Windows

Using Xojo.Core
Dim StartTime As Date
Dim Name As String

StartTime = Date.Now
Name = Name.ReplaceAll(":", "-")
Name = Name.ReplaceAll(" ", "_")
Name = Name + ".mp4"


Main.RenderShell.Mode = 1

s.Execute("a very long ffmpeg command that creates a video named with the variable name")

Sorry, code was wrong

Code is:

Using Xojo.Core
Dim StartTime As Date
Dim Name As String

StartTime = Date.Now
Name = StartTime.ToText
Name = Name.ReplaceAll(":", "-")
Name = Name.ReplaceAll(" ", "_")
Name = Name + ".mp4"


Main.RenderShell.Mode = 1

s.Execute("a very long ffmpeg command that creates a video named with the variable name")