2

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.

C. De Petter
  • 43
  • 1
  • 4

1 Answers1

1

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

ff8mania
  • 1,553
  • 3
  • 19
  • 28
  • Probably this is better as comment than as answer. – Steve Jul 31 '21 at 22:51
  • @Steve to be honest I thought the same, but for me it was actually the answer, since I resolved the same issue myself just realizing Audacity needed to be opened :) – ff8mania Jul 31 '21 at 22:54
  • Then just write the answer in a more affirmative way. So it seems that you are asking a question. (I tell you this because a BOT that looks for answers that are not answers registered your answer as such and posted the link into chat room [SOBotics](https://chat.stackoverflow.com/rooms/111347/sobotics)) – Steve Aug 01 '21 at 07:42