Invoking Python from Cygwin problem.

A

Ant

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,
 
M

Marc 'BlackJack' Rintsch

----------------------------------------------------------------------------------
#!/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.softspace` attribute) and when the
interpreter executes its shutdown code and that `softspace` attribute is
set, an extra '\n' is printed.

Ciao,
Marc 'BlackJack' Rintsch
 
A

Ant

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.softspace` 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.softspace to 0?

Cheers.
 
C

Cousin Stanley

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
 
A

Ant

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top