This script was supposed to be a quick Clearcase supporting script, it’s my first go at Python as I decided to dump Perl.
subprocess.Popen/communicate is called to run a Clearcase command that returns an empty string, however I am completely unable to accurately test for this returned value:
import subprocess
import sys
# cleartool descr -fmt "%Sn" foo.c
# returns the version number of the file if it's under CC control:
# b'"\\main\\hb_clearcase\\oint_uas_umac_03\\25"'
# or nothing if it's hijacked.
std_out = subprocess.Popen(['c:/rational/clearcase/bin/cleartool', 'desc',
'-fmt', '"%Sn"', 'foo.c'], stdout=subprocess.PIPE).communicate()
std_out = std_out.decode("utf-8")
print(std_out)
# prints: ""
# Here it goes wrong, I have tried many options in the if...
# The file IS hijacked, the std_out string IS empty.
if std_out == "":
print('File is hijacked')
else
print('File is not hijacked')
The wonder is the difference in the if std_dev == "" comparison’s behaviour between running the script directly in a DOS box or in PyDev in Eclipse. They seem to always return the opposite result. As it is above this works as expected (ie. hijacked) on PyDev, fails in the command prompt. Make the comparison if std_dev == '""' and PyDev delivers the expected result, but not the command prompt.
This is the latest Python 3.3 on Win7 and I expected to have nailed this script hours ago.
What on earth am I doing wrong?
First of all, good choice to stick to Python (see this, especially the “Alt” text when you mouse-over the cartoon).
Maybe you could try:
This will make strings like
'""'and' ""'all be like “”.Anyway, it sounds strange to me that PyDev gives a different result.