By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,715 Members | 768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,715 IT Pros & Developers. It's quick & easy.

Invoking Python from Cygwin problem.

P: n/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,

Nov 24 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In <11**********************@l39g2000cwd.googlegroups .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.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
Nov 25 '06 #2

P: n/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.

Nov 25 '06 #3

P: n/a

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 =----
Nov 25 '06 #4

P: n/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...

Nov 25 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.