Re: Use of subprocess.popen with sequence and shell=True is incorrect on linux, breaks clearcase.py

2013-03-11 Thread Jan Koprowski
We are aware of the problem. shell=True is necessery for windows 
compatilibty. This is known issue with Python 2.7.x. We are working on that.

Thanks for your awareness,

W dniu czwartek, 28 lutego 2013 15:06:46 UTC+1 użytkownik Jay Lawrence 
napisał:
>
>
>
> On Wednesday, February 27, 2013 5:29:56 PM UTC-5, Jay Lawrence wrote:
>>
>>
>> This is the root cause of the problem entitle "SCMError("Unsupported View 
>> Type" earlier on this board, but appears fundamental enough that I've 
>> started a new thread with a more appropriate title
>>
>> In the scmtools/clearcase.py file, the following idiom is used to invoke 
>> clearcase commands
>>
>> cmdline = ["cleartool", "lsview", "-full", "-properties", "-cview"]
>> p = subprocess.Popen(
>>   cmdline,
>>   stdout=subprocess.PIPE,
>>   stderr=subprocess.PIPE,
>>   cwd=repopath,
>>   shell=True)
>>
>>(res, error) = p.communicate()
>>failure = p.poll()
>>
>> if failure:
>>   raise SCMError(error)
>>
>>  for line in res.splitlines(True):
>> splitted = line.split(' ')
>> msg = "_get_view line: " + line;
>> logging.debug(msg);
>> if splitted[0] == 'Properties:':
>>if 'snapshot' in splitted:
>>   return self.VIEW_SNAPSHOT
>>elif 'dynamic' in splitted:
>>   return self.VIEW_DYNAMIC
>>
>>return self.VIEW_UNKNOWN
>>
>> The issue is with the use of a sequence as the first argument to the 
>> subprocess.popen command
>>
>> On Unix, when a sequence is used as the first argument to popen, when 
>> shell=true is set, the first element of the sequence is treated as the 
>> command. The subsequent arguments are treated as options to the SHELL. This 
>> means that in the command above, only the 'cleartool' command is being 
>> executed.
>>
>> I've seen this at multiple places on the web, most notably: 
>>   
>> http://stackoverflow.com/questions/9231074/pythons-subprocess-popen-results-differ-from-command-line
>>
>> On Linux, the cmdline should be a string, or the full command should be 
>> given as the first argument of the sequence. The following works:
>>
>>cmdline = ["cleartool lsview -full -properties -cview"]
>> p = subprocess.Popen(
>>   cmdline,
>>   stdout=subprocess.PIPE,
>>   stderr=subprocess.PIPE,
>>   cwd=repopath,
>>   shell=True)
>>
>>
>>
>>
>>

-- 
Want to help the Review Board project? Donate today at 
http://www.reviewboard.org/donate/
Happy user? Let us know at http://www.reviewboard.org/users/
-~--~~~~--~~--~--~---
To unsubscribe from this group, send email to 
reviewboard+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/reviewboard?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"reviewboard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to reviewboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Use of subprocess.popen with sequence and shell=True is incorrect on linux, breaks clearcase.py

2013-02-28 Thread Jay Lawrence


On Wednesday, February 27, 2013 5:29:56 PM UTC-5, Jay Lawrence wrote:
>
>
> This is the root cause of the problem entitle "SCMError("Unsupported View 
> Type" earlier on this board, but appears fundamental enough that I've 
> started a new thread with a more appropriate title
>
> In the scmtools/clearcase.py file, the following idiom is used to invoke 
> clearcase commands
>
> cmdline = ["cleartool", "lsview", "-full", "-properties", "-cview"]
> p = subprocess.Popen(
>   cmdline,
>   stdout=subprocess.PIPE,
>   stderr=subprocess.PIPE,
>   cwd=repopath,
>   shell=True)
>
>(res, error) = p.communicate()
>failure = p.poll()
>
> if failure:
>   raise SCMError(error)
>
>  for line in res.splitlines(True):
> splitted = line.split(' ')
> msg = "_get_view line: " + line;
> logging.debug(msg);
> if splitted[0] == 'Properties:':
>if 'snapshot' in splitted:
>   return self.VIEW_SNAPSHOT
>elif 'dynamic' in splitted:
>   return self.VIEW_DYNAMIC
>
>return self.VIEW_UNKNOWN
>
> The issue is with the use of a sequence as the first argument to the 
> subprocess.popen command
>
> On Unix, when a sequence is used as the first argument to popen, when 
> shell=true is set, the first element of the sequence is treated as the 
> command. The subsequent arguments are treated as options to the SHELL. This 
> means that in the command above, only the 'cleartool' command is being 
> executed.
>
> I've seen this at multiple places on the web, most notably: 
>   
> http://stackoverflow.com/questions/9231074/pythons-subprocess-popen-results-differ-from-command-line
>
> On Linux, the cmdline should be a string, or the full command should be 
> given as the first argument of the sequence. The following works:
>
>cmdline = ["cleartool lsview -full -properties -cview"]
> p = subprocess.Popen(
>   cmdline,
>   stdout=subprocess.PIPE,
>   stderr=subprocess.PIPE,
>   cwd=repopath,
>   shell=True)
>
>
>
>
>

-- 
Want to help the Review Board project? Donate today at 
http://www.reviewboard.org/donate/
Happy user? Let us know at http://www.reviewboard.org/users/
-~--~~~~--~~--~--~---
To unsubscribe from this group, send email to 
reviewboard+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/reviewboard?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"reviewboard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to reviewboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.