Writing to named pipe - Errno 22 in Pycharm only

Viewed 219

I'm trying to send commands to Audacity using a named pipe, which can be tested using: (https://github.com/audacity/audacity/blob/master/scripts/piped-work/pipe_test.py provided by Audacity)

import os
import sys    

if sys.platform == 'win32':
    print("pipe-test.py, running on windows")
    TONAME = '\\\\.\\pipe\\ToSrvPipe'
    FROMNAME = '\\\\.\\pipe\\FromSrvPipe'
    EOL = '\r\n\0'
else:
    print("pipe-test.py, running on linux or mac")
    TONAME = '/tmp/audacity_script_pipe.to.' + str(os.getuid())
    FROMNAME = '/tmp/audacity_script_pipe.from.' + str(os.getuid())
    EOL = '\n'    

print("Write to  \"" + TONAME +"\"")
if not os.path.exists(TONAME):
    print(" ..does not exist.  Ensure Audacity is running with mod-script-pipe.")
    sys.exit()

print("Read from \"" + FROMNAME +"\"")
if not os.path.exists(FROMNAME):
    print(" ..does not exist.  Ensure Audacity is running with mod-script-pipe.")
    sys.exit()

print("-- Both pipes exist.  Good.")

TOFILE = open(TONAME, 'w')
print("-- File to write to has been opened")
FROMFILE = open(FROMNAME, 'rt')
print("-- File to read from has now been opened too\r\n")

On a first run, with Audacity open, this yields:

pipe-test.py, running on windows
Traceback (most recent call last):
Write to  "\\.\pipe\ToSrvPipe"
Read from "\\.\pipe\FromSrvPipe"
  File "C:/Users/chris/PycharmProjects/Youtube-Spotify-DL/pipe_test3.py", line 44, in <module>
-- Both pipes exist.  Good.
    TOFILE = open(TONAME, 'w')
OSError: [Errno 22] Invalid argument: '\\\\.\\pipe\\ToSrvPipe'

Process finished with exit code 1

On a second run:

Traceback (most recent call last):
  File "C:/Users/chris/PycharmProjects/Youtube-Spotify-DL/pipe_test3.py", line 44, in <module>
pipe-test.py, running on windows
    TOFILE = open(TONAME, 'w')
FileNotFoundError: [Errno 2] No such file or directory: '\\\\.\\pipe\\ToSrvPipe'
Write to  "\\.\pipe\ToSrvPipe"
Read from "\\.\pipe\FromSrvPipe"
-- Both pipes exist.  Good.

Process finished with exit code 1

So it seems like the pipe cannot be written to and/or closes. However, when running this script through IDLE, it runs just fine. So, in what way is Pycharm preventing writing to this named pipe, and how could it be fixed? Thanks.

1 Answers

Did you open audacity before running the test script? Audacity needs to run

Related