0

I am trying to send .mp4 files to an mp4 tagging application. My problem is that on Windows everytime I call subprocess.call() or subprocess.Popen() a new process is spawned.

What I want is to open the file in the existing process if the process is already running... is this possible or will it depend on how the process being called handles new process calls?

here is what I have:

def sendToTagger(self, file):
            msg = "-- " + self.getDateStamp() + "-- Sending " + os.path.basename(file) + " to Tagger...\r\n"
            self.logFile.write(msg)
            print(msg)
            p = subprocess.Popen(['C:\\Program Files (x86)\\Tagger\\Tagger.exe', file], shell=False, stdin=None, stdout=None)
hammus
  • 2,602
  • 2
  • 19
  • 37
  • 1
    Does `Tagger.exe` accept new files via its stdin i.e., does it work: `echo filename.mp4 | Tagger.exe`? If it does then you could use a single process to process multiple media files. – jfs Nov 25 '13 at 02:18
  • @J.F.Sebastian - thanks for the repsonse! I was using MetaX yeserday when I wrote this which doesnt process files via `stdin` I've moved onto using AtomicParlsey now and everything is just peachy now. Thanks! – hammus Nov 25 '13 at 02:20

2 Answers2

1

It has to spawn a new process as you are calling external command not native to your python code. But you can, if you wish wait for the process to complete by calling p.wait()

user3020494
  • 712
  • 6
  • 9
  • it is *not* necessary to spawn a new process each time e.g., the subprocess can accept new files from its stdin. – jfs Nov 25 '13 at 02:19
0

subprocess.Popen always opens a new process (that is it's purpose). You need to determine how Tagger.exe allows another program to programmatically request it to open a new file. In the simplest case you can simply communicate with it over stdin (in which cause you need to set stdin and possibly stdout to PIPE). However, your program may require some other method of inter-process communication (IPC). Such as sockets, shared memory, etc. I am not familiar with the methods on Windows, but if Tagger is a graphical program there is a good chance that you will need to do something more sophisticated.

Thayne
  • 6,619
  • 2
  • 42
  • 67