Shell object does not have all commands

John Chittum's icon

I'm working on a Max + Csound project. One little specific is I'd like to use CSound's lpanalysis tool. For those unfamiliar with it, lpanalysis in CSound is a 2 step process--analysis via a command line argument, and then use of the analysis file. I'm attempting to call the lpanalysis command line tool. I've attempted a few methods, and the one that should have worked is the shell object:

However, I get the following:

stdout&stderr: sh: csound: command not found

Csound works perfectly fine from using iTerm2:

csound -U lpanal -h400 -p50 soundin.104 analysis/lp.initialvoice 2>&1
virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.08 (double samples) Nov 23 2016
[commit: a1159a1e12a1095c4607f7162c44b196f5143959]
libsndfile-1.0.25
util lpanal:
Using filter coefficient storage method
audio sr = 44100, stereo, reading channel 1
opening WAV infile soundin.104
analysing 221152 sample frames (5.0 secs)
552 lpc frames written to analysis/lp.initialvoice
end of score.         overall amps: 0.0
     overall samples out of range: 0
0 errors in performance
Elapsed time at end of performance: real: 0.056s, CPU: 0.056s

it prints out poorly in terminal, however, works just fine.

Thus the question: How does the shell object spawn a new shell? Which shell does it spawn? Have others run into having command line utilities not function in the newly spawned shell? My C is crap, so I'm not doing well with the code (I'm a Python and sometime Ruby dev).

Alternatively, if someone knows another way of creating the analysis file, that'd awesome.

Facts:

MacOS: 10.11.6
Max: 7.3.1 64 Bit
Sample patch and 2 scripts attempting to circumvent issues before realizing the real problem attached

shelltest.maxpat
Max Patch
Source Audio's icon

You could try using complete path to csound, like :
/usr/local/bin/csound -U etc

Source Audio's icon

But also there is csound~ object for max.
Download link at :
http://csound.github.io/download.html

John Chittum's icon

you cannot do lpanalysis in a csound file (to my knowledge). The analysis itself occurs via the command line tool to create the analysis file. I am using csound~ successfully.

I've set the path, and it appears to be working. However, I've noticed a major oddity--the working directory being used by shell is almost arbitrary.

example:

Max file housed in /Users//dev/Max/Testing/shelltest.maxpatch

pwd into shell object returns /

open another patch in /Users//dev/Max/kulala/kulala_toplevel.maxpatch

pwd into shell returns /Users//dev/Max/kulala/

After opening the kulala patch, the shell in shelltest also returns /Users//dev/Max/kulala/

I've attached the 2 maxpatches. Obviously you'd need shell, but it also has csound~ and sigmund~ in kulala

shelltest1.maxpat
Max Patch
kulala-toplevel.maxpat
Max Patch
Source Audio's icon

If You want to make sure shell works in directory where You want it to do so,
allways use absolute path.
Just as calling /usr/local/bin/csound instead of just csound

Max and shell do not work exactly the same way as executing commands from terminal .
shell.mxo was never documented in detail.

John Chittum's icon

Source Audio, did you check my patches or my comment above? I do use absolute path. It is still not working.

Could you please try my attached patches or check the work there? Max and shell should be very close to executing commands in the terminal. The source code is basically just wrapping the shell commands in C (much like using subprocess in Python). Obviously I'm missing something in how the source code is starting the shell, and where the shell lives.

John Chittum's icon

Also, using absolute path for everything makes reproducibility between machines really really hard.

"here's this piece I wrote...change these patches here, here, here, and here to work on your system." At this point, i'm going to see how long of a script I can write in one line to enter into it, just to see if I can force it to work w/o absolute path.

volker böhm's icon

absolute path is working fine for me.
btw, you could also call lpanal directly like /usr/local/bin/lpanal mySound.aif myAnalysis
there is something odd going on with the PATH variable, though.
also the error "stdout&stderr: sh: csound: command not found" seems to indicate that it's not coming from bash but from sh.
although 'echo $SHELL' returns /bin/bash in may case.
maybe the shell object starts a sh shell by default which then launches the user default shell which in most cases on osx should be bash?
i don't know.

to me it seems you can't rely on $PATH when using the shell object.
if you just want to run lpanal on different computers from your patch, you could make a copy of lpanal and place it in the same directory as your main patch. get the path to your patch by using thispatcher and use this to create the absolute path to lpanal for the shell object.
just my 2c

John Chittum's icon

Copied lpanal to local directory. Then I tried the solution of path + thispatcher + the following message

$1lpanal -h400 -p50 $1sound.wav $1testanalysis

It is definitely showing the correct directory, however, it's adding in the disk. so

computer:/Users/jchittum/MaxTesting/lpanal

And i get "no such file or directory"

When I try to run it using the exact directory returned by thispatcher in the command line, I get the same result.

Talk about infuriating. That was a great solution! Packaging lpanal with the patch is a tidbit annoying, but completely acceptable (I'm packaging externals anyway). so close! I'm gonna make this work.

Source Audio's icon

Shell will not accept path like that.
Simply remove the Harddisk Name and just leave unix style slash.
/Users/jchittum/MaxTesting/lpanal
If You need to get path from thispatcher, You can insert
{conformpath slash boot} and get the proper path for shell.

John Chittum's icon

Source Audio, TY! the conformpath object is just what the doctor ordered!

I've attached the final working test path. Assumes:

lpanal in ./bin
soundfile name soundin.104
./analysis exists

Will probably set the value during a little "init" type function. Then it'll always be handy for these things!

Much thanks!

relativecreations2.maxpat
Max Patch
Source Audio's icon

You are welcome, linking Max wit outer word is not allways easy,
and for most because of Max specific dealing with symbols and paths.