I am trying to pass a file-like StringIO object to a subprocess which expects a file "file.ly". Possible problems might be the file extension and expected apostrophes before and after the filename.
I tried:
import subprocess
import lilypond
from io import StringIO
string ='{e c}'
file = StringIO(string)
print(file.read())
file.seek(0)
subprocess.run([lilypond.executable(),"-fpng", file.read()])
The code works as expected when using:
subprocess.run([lilypond.executable(),"-fpng", "file.ly"])
("file.ly" contains "{e c}")
Here is the error message:
{e c} Warnung: Datei »{e c}« kann nicht gefunden werden schwerer Fehler: gescheiterte Dateien: "{e c}"
This translates to the following (using google translate):
{e c} Warning: Cannot find file »{e c}« fatal error: failed files: "{e c}"
I suppose that this means that the python code is OK, but the lilypond subprocess doesn't like the input.
Is there a fix for this problem?