Invoking Python from Cygwin problem.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ant

    #1

    Invoking Python from Cygwin problem.

    Hi all,

    Using cygwin and Python 2.5, I have the following scripts, one bash
    script and the other a python script:
    -------------------------------------------------------------------------------
    #!/bin/bash

    TEST_VAR=`./test.py`
    TEST_VAR2=Test2

    echo "Test var: $TEST_VAR OK"
    echo "Test var2: $TEST_VAR2 OK"

    ----------------------------------------------------------------------------------
    #!/usr/bin/python
    print "Testing",

    Running the bash script, I get the following output:

    OKt var: Testing
    Test var2: Test2 OK

    Does anyone have any idea why the script would mess up the first echo?
    Are there some kind of control characters being appended to the python
    output in Windows? Looks like a CR character, but why?

    Cheers,

  • Marc 'BlackJack' Rintsch

    #2
    Re: Invoking Python from Cygwin problem.

    In <1164385876.755 749.139020@l39g 2000cwd.googleg roups.com>, Ant wrote:
    ----------------------------------------------------------------------------------
    #!/usr/bin/python
    print "Testing",
    >
    Running the bash script, I get the following output:
    >
    OKt var: Testing
    Test var2: Test2 OK
    >
    Does anyone have any idea why the script would mess up the first echo?
    Are there some kind of control characters being appended to the python
    output in Windows? Looks like a CR character, but why?
    It's a feature. The `sys.stdout` object remembers if the last ``print``
    ended in a comma (see the `sys.stdout.sof tspace` attribute) and when the
    interpreter executes its shutdown code and that `softspace` attribute is
    set, an extra '\n' is printed.

    Ciao,
    Marc 'BlackJack' Rintsch

    Comment

    • Ant

      #3
      Re: Invoking Python from Cygwin problem.


      Marc 'BlackJack' Rintsch wrote:
      ....
      It's a feature. The `sys.stdout` object remembers if the last ``print``
      ended in a comma (see the `sys.stdout.sof tspace` attribute) and when the
      interpreter executes its shutdown code and that `softspace` attribute is
      set, an extra '\n' is printed.
      So the workaround is to directly write to sys.stdout I guess. Or set
      sys.stdout.soft space to 0?

      Cheers.

      Comment

      • Cousin Stanley

        #4
        Re: Invoking Python from Cygwin problem.


        Hi all,
        >
        Using cygwin and Python 2.5, I have the following scripts,
        one bash script and the other a python script:
        --------------------------------------------------------------
        Ant ....

        Using Cygwin and Python 2.4 under Win2K the following version
        of your code seems to work OK here with no extraneous CR ....

        I only changed the variable names & messages just a bit
        for clarity ....

        I don't see any real differences in this version
        and what you originally posted, so I can't explain
        the reason for the semingly extraneous carriage return
        that you are seeing ....

        # ------------------------------------------------------------

        #!/bin/bash

        TEST_1=`./test.py`
        TEST_2="Testing Bash Value"

        echo " "
        echo "TEST_1 : $TEST_1 .... OK"
        echo "TEST_2 : $TEST_2 .... OK"


        # ------------------------------------------------------------

        #!/usr/bin/python
        print "Testing Python Code",


        # ------------------------------------------------------------

        $ ./test_vars

        TEST_1 : Testing Python Code .... OK
        TEST_2 : Testing Bash Value .... OK


        --
        Stanley C. Kitching
        Human Being
        Phoenix, Arizona


        ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
        http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
        ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

        Comment

        • Ant

          #5
          Re: Invoking Python from Cygwin problem.


          Cousin Stanley wrote:
          ....
          Using Cygwin and Python 2.4 under Win2K the following version
          of your code seems to work OK here with no extraneous CR ....
          Hmm. Just tried it here at home (Python 2.5) and it works fine as
          well... Cygwin was pre-installed on my machine when I started work at
          the new job a couple of weeks ago. I wonder if it's an old version they
          had installed. I'll try updating Cygwin at work and see what happens...

          Comment

          Working...