I have an app that executes a python script. I call the python script from
shell.execute(thePythonFilePath)
This works if I add the word "python " to the front of the path. Now I would like to pass two parameters, also file paths, to the python script.
I have tried this
shell.execute(thePythonFilePath,1filepath,2filepath) // all as strings
shell.execute(thePythonFilePath+" "+1filepath+" "+2filepath) // all as strings
shell.execute(thePythonFilePath+"'"+1filepath+"'"+2filepath) // all as strings
All these fail. I have looked at lots of documentation but seam to get conflicting answers. Can some shed some light?
#2 “should” work, assuming “thepythonfilepath” starts with "python " followed by the script name/path
#3 might work under the same conditons, and if you changed "’ " to “’ '” instead (you have a single quote starting each argument, and no ending quote)
type replacing “shell.execute” with “msgbox” so you can “SEE” the full command line
and then paste it into “terminal” to see that it truly does work
make sure the command is started with the actual full path to PYTHON itself since a SHELL does NOT have any of your environment set up (ie/ the paths to executables etc) You can get this by opening Terminal on macOS and typing in “which python” and you will get the full path to it
the path to the python file needs to be a full & properly escaped POSIX path (this is FolderItem.ShellPath)
the paths to the other two items also need to be fully escaped POSIX paths (this is FolderItem.ShellPath)
OK so whats an escaped posix path ?
Well IF you are on macOS and open Terminal and drag file in there that has special characters in the name (spaces etc) you can see the name may have \ in it (Windows & linux consoles work similarly)
These act as “escapes” saying “the next character LITERALLY” so you can embed a number of special characters in a name and they get interpreted right and NOT handled by the command interpreter (bash, csh, zsh etc)
so you might end up with
shell.execute(thePosixPathToPython + " " + thePosixPathToThePythonFilePath+" "+PosixFilepath1+" "+PosixFilepath2) // all as strings
I am already sorting the Posix path as I add "python " to the front of the shell path to the script. My python script writer told me to put that there and now I know why.
I have inserted "\ " between shell paths and that appears to work so far, I need my python guy to see if the argument go through, I’m not getting an error.
"\ " would make sense as a space on it’s own was being stripped out, but adding \ forces it to be read?