#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    17
    Rep Power
    0

    A couple of simple questions


    I have two questions that I can't figure out for the life of me. Any and all help will be greatly appreciated:

    1. Given the following, os.system refuses to "find" the path:

    Code:
    os.system("C:\\Program" + " " + "\Aqsis\\bin\\aqsis.exe")
    It should find C:\Program Files\Aqsis\bin\aqsis.exe The key problems lies in the space between Program and File and I can't escape a space.

    and one more question.

    2. I have a program (a 3d renderer) listening on stdin. I know its listening because if i go to my prompt and type stuff in, it'll respond (with an error message saying it didn't like my gibberish). I run this python program that prints stuff to the screen (print "foo") which I assume to be stdout. Yet the renderer does not recieve the communication.

    I generalized what I'm seeing to these two programs:

    Run this first:
    Code:
    #!/usr/bin/env python
    
    import sys
    
    # this should read from stdout
    foo = sys.stdin.readline(100)
    then print something to stdout, so it can be read...
    Code:
    #!/usr/bin/env python
    
    import sys
    
    sys.stdout.write("Is anyone home")
    
    # alternatively, we could do 
    # print "Is anyone home?"
    But the first program does not recieve and print out any input from stdin. What misconception am I laboring under? Thank you for your time.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    Originally Posted by ktpr
    I have two questions that I can't figure out for the life of me. Any and all help will be greatly appreciated:

    1. Given the following, os.system refuses to "find" the path:

    Code:
    os.system("C:\\Program" + " " + "\Aqsis\\bin\\aqsis.exe")
    It should find C:\Program Files\Aqsis\bin\aqsis.exe The key problems lies in the space between Program and File
    The space between Program and ... what?

    If it still doesn't work with 'Files' in there, then wrap the string in quotemarks such that the outer pair indicate a Python string, and the inner pair indicate to the OS behind os.system that the path is all one string, so:

    Code:
    os.system('"C:\\Program Files\\Aqsis\\bin\\aqsis.exe"')
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    As for your second question, are you running the two python programs in different terminal windows or what? If you want the output of one program going to the input of the other, you would execute them both and connect them with a pipe (|) in the command line
    $ ./outputter.py | ./inputter.py
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    17
    Rep Power
    0
    I posed my second question poorly. What I want to do with piping is open up a pipe to write to, then feed it arguments and finally have the program at the end of the pipe execute. I know this is possible but I can't isolate an example outside of a package I'm tinkering with.

    In this example the DOS command md (make directory) should make a directory after being given its arguments. But it doesn't.

    Code:
    #!/usr/bin/env python
    
    import sys, os
    
    class SimpleStream:
        """Encapsulates the output stream."""
        
        def __init__(self, outstream):
            self.out = outstream
    
        def close(self):
            self.out.close()
    
        def flush(self):
            """Flush the internal buffer."""
            self.out.flush()
    
        def write(self, data):
            """Write data into the stream."""
            self.out.write(data)       
    
    
    name = "md"
    
    outstream = os.popen(name,"w")
    
    
    s = SimpleStream(outstream)
    
    s.write("hello")
    
    s.flush()
    s.close()
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    73
    Rep Power
    10
    for you first Question, I hope this help a little

    Program files ==> 'progra~1'
    My documents ==> "mydocu~1"
    Documents and settings ==> "docume~1"

IMN logo majestic logo threadwatch logo seochat tools logo