This is a wrapper program that uses the xmp binary to play mod files at random. However, I would like to have another process running so that if a good song is playing I can write the name of the filename to a file for future reference.
Code:
#!/usr/bin/python
# -*- coding:utf-8 -*-
"""
wrapper for xmp
to play random files
"""
import random
import os
import sys
def main():
files = os.listdir('/Users/rgonzale/Mods')
command = "/usr/local/bin/xmp /Users/rgonzale/Mods/%s" % (files[random.randint(0,(len(files) - 1))])
pid = os.fork();
if pid > 0:
os.system(command);
if pid == 0:
c = sys.stdin.read(1);
if c == 'e':
print "hope this works"
if __name__ == "__main__":
main()
When the parent runs the command it has stdin, stdout, and stderr to the pty that I ran the process from. The character 'e' is not a character that xmp will do anything with from stdin, I checked in the man page. When I have the child try and read a char from stdin, I can't get it to print "hope this works".
At the point where the os.fork() occurs, do both processes have stdin, stdout, and stderr all tied to the pty I am in? When it is forked, I understand that the child has an exact copy of all the file descriptors which should include stdin, stdout, and stderr that are similar to those of the parent.
I think I need to be using the termios module. However, the documentation for the Python termios module is slim to none. It is also a little hard to grasp. Could somebody give me an example of how I would use that module in my specific case?