Since you have two eyes
But only one works.
Talking about work, we do not get that in the Terminal.
Since you have two eyes
But only one works.
Talking about work, we do not get that in the Terminal.
Yes, you are right, I do not checked in the Execute button is there is some selected code and report the error. But I always select a command to execute.
The provided code is executed with the default mode.
Setting the working folder does not works whatever mode I use.
Now if you think Xojoâs Shell works fine, good, but I still have to see it to believe it (that is the St Thomas in me who speaks).
I nearly forgot: what I want to do with Xojo works fine when I do it with the Terminal.
You, probably. You just forgot to tell us
Well, thatâs not important.
With default mode (and asynchronous mode), you canât issue several commands to be executed together, thatâs the whole point.
Both of them execute a single command in a âbrand newâ environment.
So, they work like that, with your attempt:
Set working directory.
<new shell environment; resets working directory, among other things>
List working directory (which, as has been reset, is the default directory of the shell)
⊠and so on.
You have to use mode 3 (interactive) to execute a list of related commands.
Have you looked at the documentation for the Shell class?
Youâre doing it wrong in your example project. In interactive mode (the one you must use here), you start by executing the first command (using the Execute method), subsequent commands are then issued using the WriteLine method (no longer the Execute method, used only at the beginning), when you get the result of the current command (so, you send the next command when the current one has finished and has triggered the Completed event). Take a look at the ExecuteMode property of the Shell class, in the language reference.
St-Thomas also had to make correct tests to get correct results
Thank you for your explanation, but I still donât get it.
Using the same steps, in the Terminal it works, with this project it behave differently. And so, whatever the mode is (Interactive or not).
All I wanted was to use that example as I do in the Terminal.
I read the (far above link) documentation and use it to display the env
data; yes, there is a second window (click in âShow Environmentâ).
I only want to do some basic tasks; the first one is to set the working directory as I do in the Terminal. But, maybe I have to stay with the Terminal, after all.
Last modifications:
The Environment window (High Sierra, is different on M1 / BS).
Letâs think about it the other way around. If you take the Terminal, you can also act like your current Xojo code: that is if you close every Terminal window between each command, like this:
(Terminal window)
cd /users/me/desktop
(Close Terminal window)
(Open new Terminal window)
mkdir âEmileâ
(Close Terminal window)
(Open new Terminal window)
ls -l
(Close Terminal window)
Try it that way and youâll get the same behaviour as with Xojo.
Try this in an empty Xojo project:
Add a new class to the project, name it âCMyShellâ and of type âShellâ. Add a property âCurrentStep As Integerâ to it.
Add the DataAvailable event to this class and put this:
Select case CurrentStep
case 0 'First command
me.WriteLine "cd /Users/Me/Desktop/" //Replace Me by your username, of course
case 1 'Second command
Me.WriteLine "mkdir ""Test"""
else 'Finally
me.Close
Return
end Select
CurrentStep=CurrentStep+1
In the main window, add a property: âMyShell As CMyShellâ.
In the windowâs MouseDown event, put this:
MyShell=New CMyShell
MyShell.ExecuteMode=Shell.ExecuteModes.Interactive
MyShell.Execute "sh"
Do you get the idea?
I think so.
In the first (ans following) version of the shared project, I had a window Property that I use all around (I think; itâs hard to remember when I use the project once a day or so, sor some minutes only).
The trick "do something in the Terminal, then close the window, open anther and check what you getâ is⊠awesome. I never do that before (in the same âsessionâ).
I will read your code later today (itâs 1H40 at night right now, time to bed).
Thank you for your tips and explanations.
Amazing. I posted the solution a few days ago, but it seems not to have been understood. It should be simple enoughâŠ
That is how you select the working directory, and do everything in the same shell session.
Well, I understood it, but wanted to explain an interactive method (that is, for example, when not all commands are known in the beginning).
I also have to confess that this all-in-one-line format isnât something I usually dealt, so, by lack if habit, itâs not the path I easily follow.
But I thank you for having posted it; itâs certainly a great way when you have a list of known commands to pass.
I read your mail Michel, but I do not wanted to issue many commands on the same line.
Iâm not at home, so I will check later, but your example line returns:
mkdir: zoe: Read-only file system
then:
bash: line 0: cd: zoe: No such file or directory
The working folder is the rootâs boot HD folderâŠ
Are you using Michelâs example here, or your own with specifying the current directory?
(note that Michelâs example creates a folder as the first command, which may fail with the error you get, since the current folder isnât set).
Thatâs expected when the previous command fails.
A guess or you specified it?
sigh ;(
There are two ways to keep the environment: with a single line containing several commands separated by the end of line character (;), or by creating a bash script. The issue with the bash script is that it needs to have the execute bit set with chmod, through yet another shell, after it has been created, and before executing it.
I donât know any way to keep the working directory between shell sessions. If you need a terminal, your best option is to use the Terminal.
Thank you Michel; I will drop Xojo and go back with the Terminal.
Write the result of a call to pwd into a var and then âcdâ into it at the start of the next terminal session. Thatâs the way that I do it if I have to close and reopen a terminal session in Shell.