shell

volker böhm's icon

Thanks for the swift reply.
Unfortunately @forkmode 1 doesn't change anything here.

Jeremy's icon

Hm, it worked for me on macOS 11.6.3. Maybe Apple has killed vfork (or aliased it to fork) on macOS 12.

Fixing this perfectly will probably require some extreme re-engineering of shell (where its spawned process is basically always running as a server and we pipe commands to it for execution). And while that model is probably a better way to go in general, it's going to involve some work. Can't say when that work will happen, though.

volker böhm's icon

ok, thanks for letting me know. have to look for another solution then.
For the record, tried the current shell (Jul 2021) on mojave and it works fine.
Also quickly checked out the old shell (commit from oct 2018) on github, recompiled for arm64 and found the same problem with the drop outs. Seems definitely related to macOS 12

Julien Vincenot's icon

Hi Jeremy, Can you please explain a bit about the @forkmode?

I asked exactly the same question as Volker on July 20 2021 here, regarding audio dropouts — only difference is I'm using 10.14 Mojave.

Back then you simply replied about "using a different fork" but without giving any detail on what it was or how to use it. And obviously there's nothing about in the help file, I first hear of the attribute today :(

Jeremy's icon

Well now you know! Sorry for the incomplete information last July.

At least up until Big Sur, there are two types of fork available on macOS, fork() and vfork(). vfork() works differently under the hood and is significantly faster.

If and when I do the rewrite alluded to above, it won't matter anymore, since the object will fork at instantiation time and that extra process will just wait around until there's something to do.

Julien Vincenot's icon

I see, thanks !
So just to clarify, @forkmode 0 (default) is fork() and @forkmode 1 is vfork(), correct?

I will make some tests with my Lisp system and hopefully it does the trick for now.
I also have a machine with Big Sur — I don't use much for a while — I'll also give it a try.

Jeremy's icon

Correct -- you can see the labels in the inspector. Thanks for trying it out.

Julien Vincenot's icon

Indeed I completely missed that, thanks Jeremy !

fraction's icon

hi,
on windows machine, i m struggling to find the right syntax to delete a file.
Lets say my that is C:/Users/PC/Desktop/mytest.png
I tried commands like : rm, del, but doesnt work, also with ~, using relative or absolute path, without success.

What would be the syntax to delete a file from shell?
thx!

Source Audio's icon

del is ok, but you probably mess the path.

use conformpath native_win boot and route it to message del $1 > shell.

that would also accept ~Desktop/mytest.png


Andy Maskell's icon

On Windows the folder delimiter is a backslash (\) not a forward slash (/)! As Max sees \ as a special character, you have to double them up. So you'd have to use:

C:\\Users\\PC\\Desktop\\mytest.png

fraction's icon

Thanks a lot @Andy ! :)

joseph larralde's icon

Hello, I'm actually using the shell object (on windows 10) to manage lifecycles of OpenVibe scenarios.
This is working great except that OpenVibe's python scripting box cannot be initialized, probably because Python is not in the PATH returned by the echo %PATH% command.
I tried the setx /M "%PATH%;C:\Program Files\Python37" command but got a "register access refused" error.
OpenVibe relies on the users installing Python 3.7.8 (exactly) on their own so I can't see another way to proceed here ...
Any advice ?
Thanks in advance,
Joseph

Source Audio's icon

Did you try to use absolute path to python executable ?
like
C:\Program Files\Python37/python (script to execute)

joseph larralde's icon

Hi source audio, and thanks for your quick answer
Unfortunately the scripts are loaded by OpenVibe (which is a visual programming environment too) from an inner python plugin, so I can't call the python binary directly. And anyway the python plugin isn't initialized because OpenVibe doesn't find python.
Right now I'm trying to set the PATH temporarily with something like SET PATH="%PATH%;C:/Program Files/Python37" && echo %PATH% && <launch openvibe command>
At this point I'm stuck because I don't succeed to generate a symbol with a quote inside (for PATH="...."), but this is more a max symbol formatting issue I think, although I'm not sure this will work once the issue is solved ...
Still digging. I'll go ask questions on the OpenVibe forum too in case I missed something.
Will keep you posted, any suggestions still welcome
Cheers,

Source Audio's icon

fighting max symbol and message formatting at same time with unknown scripting language is for sure
frustrating, because you can't tell exacltly what is wrong.
Can you try to execute your commands from command prompt to verify the code,
and then try to recreate it in max & shell ?



joseph larralde's icon

Yes, it works perfectly fine from the command line interpreter, OpenVibe not finding python is the only error I was encountering when launching from Max.
Meanwhile I figured out I could write "PATH=..." instead of PATH="..."
I was about to report that it still doesn't work but in fact IT DOES :)
It's just that set "PATH=%PATH%;C:/Program Files/Python37" && echo %PATH% doesn't show the python path appended at the end (which is very weird, considering it is actually appended because it works)
Any explanation of this unexpected behaviour would be appreciated, but for now I can move on.
Thanks for the support !

Arnau Brichs's icon

Hello, I'm trying to run this very simple "cat" command and I get nothing back (it does work on the normal terminal).

cat <(head -n4 /Users/arnaubrichs/Desktop/temp.txt) <(echo 'some input text') <(tail -n +5 /Users/arnaubrichs/Desktop/temp.txt) > /Users/arnaubrichs/Desktop/output.txt

pdelges's icon

I try to generate HMAC signatures with shell.
When I use the Terminal (OSX.14), I get the same result as from https://www.freeformatter.com/hmac-generator.html#before-output
But I don't when using the [shell] object. See this example :

Max Patch
Copy patch and select New From Clipboard in Max.

Any ideas?

Andy Maskell's icon

I run Windows and not Mac so I don't know for certain but as [shell] is running from inside Max rather than from within the OS itself, isn't the signature going to reflect that the request came from a different source? I presume that [shell] will have to put some sort of "wrapper" around your command string so that the OS knows where to send the reply back to; so if your signature depends on the source that generated it, it will see the two sources (OS and [shell]) as two different things. I'm wondering if there is an alternate "third party" app to Terminal that you could run on the Mac as a command line editor to see if that does a similar thing?

pdelges's icon

Andy, the signature doesn't depend on the source.
But anyway I think I found the reason of this problem: the echo command used by shell doesn't accept the -n option. I need to use /bin/echo -n instead to get the right result!

msnf's icon

Hi all,
I have a problem with special characters (I think...) with commands for shell thru "shell" object:
1 - I take a space of disk like this command:
Get-WmiObject Win32_logicaldisk
in Max with shell is like this
powershell -command \"Get-WmiObject Win32_logicaldisk\"
and it's work very well

BUT

2 - when I put more then one disk I need to add a filter like this:
Get-WmiObject Win32_logicaldisk -Filter "DeviceId = 'C:'"
But as you can see there are now simple and double quotes and I don't know to resolve this to send to shell object without the errors. I tried this:

powershell -command \"Get-WmiObject Win32_logicaldisk -Filter \"DeviceId = 'C:'\"\"
but doesn't work

Do you have any idea where is the problem or how it's possible to do it?

thanks a lot

msnf

Source Audio's icon

this is ok:
powershell -command "Get-WmiObject Win32_logicaldisk"

this is ok:
powershell -command "Get-WmiObject Win32_logicaldisk -Filter 'DeviceID = ''C:'''"

keep doublequotas only at start and end of command

'DeviceID = ''C:''' <-- this are all single quotas, 6 in total

msnf's icon

thanks Source Audio for your answer,
but be careful , the PS command is this:
Get-WmiObject Win32_logicaldisk -Filter "DeviceId = 'C:'"

and I need to put it inside shell object
for this at first I need to put the firsts quotes for the whole command:
" Get-WmiObject Win32_logicaldisk -Filter "DeviceId = 'C:'" "
and backlashed them:
\" Get-WmiObject Win32_logicaldisk -Filter "DeviceId = 'C:'" \"

but there are still other quotes inside and this is the pb.

In your answer your 'DeviceID = ''C:''' is not correct for the command - it's like this "DeviceId = 'C:'"

Source Audio's icon

you didn't even try it, or ?

msnf's icon

YES you are right!
very special but working like a charm ;-)
THANK YOU very much Sound Audio
msnf

msnf's icon

Hi,
I have one problem/question with shell:
I would like to work with ftp/sftp commands on Mac/Win os, but is it possible?
When I work with ftp on Win or sftp on mac I entry inside the soft with a new prompt:
ftp>
or
sftp>
and I don't have the output from the shell object.
Is there is anybody with some experience with this? Is it possible or not?
Some suggestions?
MSNF

pdelges's icon

I'd rather use node.js, which is a portable solution.
Maybe with the help of https://www.npmjs.com/package/basic-ftp

msnf's icon

thanks for the idea, but unfortunately we can't do it :(
===============================
I just found the solution for ftp on windows (maybe useful for somebody?):

ftp -n -s:ftpcmd.txt

the -n will suppress the initial login and then the file contents would be: (replace the 127.0.0.1 with your FTP site url)

open 127.0.0.1
user myFTPuser myftppassword
other commands here...

This avoids the user/password on separate lines where the first 2 lines of the file specify the username and password used for authentication.

source: https://serverfault.com/questions/235684/ftp-windows-command-line
I just tested it and it's work very well!

The next step is sftp ....

msnf's icon

OK, the previous commands works in Windows and shell, but impossible to do it on Mac...
somebody has any idea how to write ftp commands on Mac?
On windows is like this:
powershell -command \"ftp -in -s:C:\\Users\\XXX\\Documents\\ftpcmd.txt\"
and works very well
but on Mac os x:
ftp -in -s:/Users/XXX/Desktop/ftpcmdget.txt
doesn't work at all...
Somebody knows what's wrong with this?

Ewoud Van Eetvelde's icon

Hi I am using macOS Monterey 12.0.
The shell object is not working in max, also tried opening max under rosetta, any ideas?

msnf's icon

Mac Os 12.6.6 - is working here
what is meaning "not working" ?

Roald Baudoux's icon

Hello,

Is it possible to run a node script using shell on macOS?

I've tried a cd command to the server directory and then node . but it doesn't work.

Jeremy's icon

What exactly doesn't work? Does it find a node binary? There's nothing special about node wrt `shell`, so it should be possible, but I'd need more information.

Source Audio's icon

set shell wd atribute to node absolute path ?

Roald Baudoux's icon

All right. Here's a more detailed explanation: I have an existing node script which starts a Web server (it is not linked to the node.script stuff from Max) which I open in a browser.


So, the node script is in a folder outside the patcher's folder. I want to start the node script with the shell. So I send the command :

cd /Users/xxx/Documents/Programmation/spat_with_web_server_V2 && node .

Please note the dot at the end. What doesn't work is that the sever doesn't start. If I try to connect to it in the brower it's not responding.





Roald Baudoux's icon

Isn't beginning the prompt with a "cd" supposed to give an equivalent result to setting the "wd" attribute?

Roald Baudoux's icon

Well, setting wd to my server directory and then sending the command "node ." doesn't function either.

Jeremy's icon

First thing: make sure the command works as-is in the Terminal.

My best guess is that you need to start your server as a background process, otherwise it will be terminated when shell returns. So stick a & at the end and see if that works?

Roald Baudoux's icon

Yes the command works in the terminal. Sadly "node . &" doesn't. "node server.js &" neither.

MMa's icon

hi,

how can I format a text in max to launch a shell program in Windows?

Jeremy's icon

@roald, what does 'which node' return?

Jeremy's icon

@mma you need to format the message as in the cmd.exe terminal. In Max, the \ needs to be escaped (as \\), otherwise it's pretty much the same as what would work in cmd.

MMa's icon

@jeremy Unfortunately, yesterday this formatting didn't work, but today it works perfectly.

Many thanks!

So, I am trying to work with it on an M1, but the module is brown. Does it not work with these processors?

Jeremy's icon

Sounds like you don't have the most recent version. Back up to the first post, the latest supports Apple Silicon.

msnf's icon

Hi all,

I try to start and stop TighVNC on windows 10 with ps commands.

I have two commands

for start:

cd "C:\Program Files\TightVNC\"; .\tvnserver.exe

and for stop:

Stop-Process -Name tvnserver

All is work fine with start command. Only change is like this in the message object for "shell" object:

cd \"C:/Program Files/TightVNC\" && \"./tvnserver.exe\"

and TightVNC is starting - it's great!

but impossible to stop it....!

I send this message to "shel" object:

powershell -command \"Stop-Process -Name tvnserver\"

but nothing is happening :-(

where is the pb? I tried with this variation:

powershell -command \"Stop-Process -Name \"tvnserver\"\"

and this

powershell -command \"Stop-Process -Name 'tvnserver'\"

but TightVNC is still running.

Into PowerShell program the command:

Stop-Process -Name tvnserver

is working well!!!

is there somebody with the solution or idea what to do?

thanks!

Jeremy's icon

did you try 'pkill'?

msnf's icon

no, here are two commands I found:

top-Process -Name tvnserver

top-taskkill /IM tvnserver /

to use directly in Powershell, but only the first one is working.

I didn't find "pkill" command special for powershell, only for Linux and I didn't find how to use it with PS or shell in Max... :-(

don't understund where is the pb with the command which is working inside Powershell but not into shell maxmsp

Jeremy's icon

I think the misunderstanding is that the shell object isn't a terminal, it spawns a single shell which is the only thing running inside of it. So when you run cd \"C:/Program Files/TightVNC\" && \"./tvnserver.exe\", `tvnserver.exe` is running and in the foreground. You cannot interact with it further -- it doesn't have an input pipe to accept commands, like ssh or similar. So if you want to make it stop, send the message pkill to the shell object -- that's a Max message which tells the object to kill off the shell process and whatever is running in it.

I suppose in theory you could try to start the server in the background -- this isn't so straightforward on Windows, though: you can try some stuff from this SO, maybe. And then possibly your powershell command would work.

But no guarantees, this stuff is fiddly and not always easy to manage, especially on Windows.

Source Audio's icon

you can start tvnserver by sending it's path to shell

for example :

"c:/Program Files/TightVNC/tvnserver.exe"

to kill it send :

pkill, taskkill /F /IM tvnserver.exe

to shell

msnf's icon

WOW!

it's working great and immediately!!!

thank you very much Source AUDIO

msnf's icon

Hi, is there possibility to write shell command like administrator?

thanks

Source Audio's icon

yes, it is possible.

which OS ?

post also what command you want to use, it might make a difference.

msnf's icon

OS: Windows 10

commands: "net start/stop tvnserver/AnyDesk"

why the difference?

Source Audio's icon

because on mac OS you need to call sudo and enter password.

On windows, one needs to elevate script.

there are options like creating a script, adding elevated exec rights, then calling that from max.

or bat to exe with admin rights set.

that is ok if you just need that one command.

You can also use elevate.exe for that, there are several compiled binaries,

for example

you pass your command to it.

then there are some powershell commands, like

powershell

start-process PowerShell -verb runas

I am not really daily windows user, and can't tell you what is easiest ...

msnf's icon

Great and thank you very much SOURCE AUDIO!

I will try all this. For the moment I found the solutions with the .bat files... but there are some others pbs ;-)