In my project I get error= 1; or “The Shell is closed…” if I check if it is running.
The Documentation code below works until I modify it (see code below):
Var s As Shell
s = New Shell
#If TargetWindows Then
s.Execute("dir")
#ElseIf TargetMacOS Or TargetLinux Then
s.Execute("ls -la > liste.txt") // I add " > liste.txt"
#EndIf
If s.ExitCode = 0 Then
TextArea1.Value = s.Result
Else
MessageBox("Error code: " + s.ErrorCode.ToString)
End If
Without my addition ( > liste.txt), the code works fine.
A xojo shell is NOT a terminal, the whole terminal profile is missing. You miss the PATH variable and many more environment variables.
You can do however in interactive mode:
// sh needs to be in interactive mode for this to work:
sh.Execute("PATH=" + System.EvironmentVariable("PATH")) // Sets the PATH env variable in the shell
sh.Execute("cd /my/working/dir") // Folder where liste.txt is located
sh.Execute("ls -la >> liste.txt") // exectue the command
One “>” could be enough altough mac uses zsh instead of bash and may be different.
I’ve made my own code as interactive mode without success (before opening this thread)…
I even pass “full path” for either the data base and the csv files (./Users/ etc.).
I do not use Control characters, but I try not been stuborn, so the code is:
Var s As Shell
s = New Shell
s.ExecuteMode = Shell.ExecuteModes.Interactive
s.Canonical = True
#If TargetWindows Then
s.Execute("dir")
#ElseIf TargetMacOS Or TargetLinux Then
s.Execute("ls -la")
#EndIf
If s.ExitCode = 0 Then
TextArea1.Value = s.Result
Else
MessageBox("Error code: " + s.ErrorCode.ToString)
End If
The only addition to the Documentation example (that works as is) is these two lines:
So what’s the issue? The examples don’t work? then please report it in xojo issues.
What is specificly your problem that’s not working now?
s = New Shell // s must be a property of window or app or such...
s.ExecuteMode = Shell.ExecuteModes.Interactive // < event based
s.Canonical = True // < line based
#If TargetWindows Then
s.Execute("set PATH=" + System.EnvironmentVariable("PATH")) // set this path env on windows
s.Execute("dir")
#ElseIf TargetMacOS Or TargetLinux Then
s.Execute("export PATH=" + System.EnvironmentVariable("PATH")) // set this path env on linux/mac
s.Execute("ls -la")
#EndIf
// This \/ \/ \/ won't work, you NEED to use the events...
//If s.ExitCode = 0 Then
// TextArea1.Value = s.Result
//Else
// MessageBox("Error code: " + s.ErrorCode.ToString)
//End If
I only wanted to share with Xojo code how to export to a .sqlite TABLE to .csv (because Xojo does not implemented that in SQLite Data Base) while I had some minutes to use to do that. Minutes were expanded to hours.