1

I'm having an issue with this call I can't seem to resolve:

os.system('matlab -nodisplay -nosplash -r \"processFates;dlmwrite(\'' + FWHM + ' ' + volume      + ' ' + key + ' ' + str(numTrials) + '\", min_timing)\"')

FWHM, volume, key are all strings. I keep getting the error of an extra ) but it seems like I need all of them here.

1 Answer 1

2

Let's try this with some values:

>>> FWHM, volume, key, numTrials, min_timing = 'a', 'b', 'c', 'd', 'e'
>>> print('matlab -nodisplay -nosplash -r \"processFates;dlmwrite(\'' + FWHM + ' ' + volume      + ' ' + key + ' ' + str(numTrials) + '\", min_timing)\"')
matlab -nodisplay -nosplash -r "processFates;dlmwrite('a b c d", min_timing)"

See that double quote after the d? That should probably be a single quote. Also, the min_timing you're passing is the literal string min_timing, not the variable you're expecting.

Using subprocess.Popen instead of os.system you can avoid some of these problems with escaping by not relying on the shell and passing the arguments as strings directly:

command = "processFates; dlmwrite('%s %s %s %s', %s)" % (FWHM, volume, key, numTrials, min_timing)
proc = subprocess.Popen(['matlab', '-nodisplay', '-nosplash', '-r', command])
Sign up to request clarification or add additional context in comments.

3 Comments

Ah I see okay. But matlab still doesn't seem to be executing dlmwrite still.
this suggests that your syntax of the dlmwrite command is not right, you should need to have commas between the parameters, and quote the string parameters... I just indicated the problems with the shell syntax. I don't use matlab, so I can't really help you with that.
Okay. So the first one you fixed is actually giving me the result I needed without using the subprocess module. Matlab would process my parameters but not tell me it did anything (which is weird) but it works. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.