1

I am running a main script on windows 10 that calls another script called audioplayer.py using the subprocess module in python.

I want to send some input arguments when calling the audioplayer.py. So I wrote the main script as follows:

The following is the main script:

from subprocess import call call(["python", "C:/Users/Jeff/Documents/audioplayer.py", "hey.wav"]) 

The following is my audioplayer.py:

"""OpenAL playback example.""" import os, sys, time from openal.audio import SoundSink, SoundSource from openal.loaders import load_wav_file if len (sys.argv) < 2: print ("Usage: %s wavefile" % os.path.basename(sys.argv[0])) print (" Using an example wav file...") dirname = os.path.dirname(__file__) fname = os.path.join(dirname, "default.wav") else: fname = sys.argv[1] sink = SoundSink() sink.activate() source = SoundSource(position=[10, 0, 0]) source.looping = True data = load_wav_file(fname) source.queue(data) sink.play(source) source.position = [source.position[0], source.position[1], source.position[2]] sink.update() time.sleep(2) print("playing at %r" % source.position) 

But I keep getting the following error even though the file does exist in the same directory as audioplayer.py

FileNotFoundError: [Errno 2] No such file or directory: 'hey.wav' 

If I remove the hey.wav in the main script, it runs fine. It just doesn't seem to take any arguments.

1
  • 1
    'hey.wav' is a relative path, but it is not relative to the py file - it is relative to the current working directory. Commented Aug 19, 2020 at 0:43

1 Answer 1

1

try this:

call(["python", "C:/Users/Jeff/Documents/audioplayer.py", "C:/Users/Jeff/Documents/hey.wav"]) 

When you run the last one, the dir is the same with the main.py instead of the audioplayer.py.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.