Running a pvpython function in MATLAB

1 view (last 30 days)
Hi all,
I'm trying to run a ParaView Python function using the "system" command but nothing is working. I can run scripts, but now I'm working with a function and failing to pass arguments to it.
I've been trying many variations of this command
system("'C:\Program Files\ParaView 5.8.0-Windows-Python3.7-msvc2015-64bit\bin\pvpython.exe C:\path\fileName.py arg1 arg2 arg3");
This particular syntax produced this error: The filename, directory name, or volume label syntax is incorrect.
system(['C:\Program Files\ParaView 5.8.0-Windows-Python3.7-msvc2015-64bit\bin\pvpython.exe C:\path\fileName.py ', arg1,' ', arg2,' ', arg3]) %Keeping in mind that the args are strings.
but I've been getting 'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Any idea how to pass arguments to this function?
Thanks!

Accepted Answer

Amin Kassab-Bachi
Amin Kassab-Bachi on 14 Jun 2021
SOLVED
Two Things had to change.
1- In the python script itself, I removed the "def" line. and declared the arguments as follows:
arg1= sys.argv[1]
arg2= sys.argv[2]
arg3= sys.argv[3]
Please note that sys.argv[0] is the file name.
2- Then, in MATLAB I declared the arguments
arg1= '"string1"'
arg2= '"string2"'
arg3= '"string3"'
3- Then executed the command
system(['"C:\Program Files\ParaView 5.8.0-Windows-Python3.7-msvc2015-64bit\bin\pvpython.exe" "C:\ path\fileName.py" ', arg1,' ', arg2,' ', arg3])
Note: The quotations and double quotations had to be used in this way. Otherwise, the system either did not recognize the paths or did not understand you have arguments, in which case I did not even get an error because matlab considered the script had run successfully, but the script returned no results.
Hope this is useful!

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by