<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:9.0pt'>A subtle issue of a missing shebang in an executable script revealed how Python&#8217;s platform-independent versions of os.execlp, os.execlpe deviate from the native operating system implementation (in my case, Linux CentOS and SuSE). Googling during a debug session didn&#8217;t provide an obvious answer to the issue (observed in a call to subproces.Popen), and this caused a little head-scratching before figuring out the cause.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt'>I have no objection to the difference in behavior (in fact, I believe the Python behavior is safer!), but I do believe a clear warning in the documentation for os.execlp and os.execlpe is in order, stating that they do not necessarily behave the same way as the underlying OS implementation, and that, in particular, header processing (shebang #! lines) is different: presumably, the executable &#8220;must&nbsp; be either a binary executable, or a script starting with a line of the form &quot;#! interpreter [arg]&quot;.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt'>This comes from forwarding the family of os.exec* functions to os._execvpe, which itself forwards to posix.execve or posix.execv, instead of the underlying operating system versions of execlp and execvp (neither of which are available from the posix module).<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt'>Thank you and kind regards,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>$ man execve<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>[&#8230;]<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; filename&nbsp; must&nbsp; be either a binary executable, or a script<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; starting with a line of the form &quot;#!&nbsp; interpreter&nbsp; [arg]&quot;.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>[&#8230;]<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>$ man execlp<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>[&#8230;]<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Some of these functions have special semantics.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The functions execlp and execvp will duplicate the actions<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; of&nbsp; the&nbsp; shell&nbsp; in searching for an executable file if the<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; specified file name does not contain a slash&nbsp; (/)&nbsp; charac&shy;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ter.&nbsp;&nbsp; The&nbsp; search path is the path specified in the envi&shy;<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ronment by the PATH&nbsp; variable.&nbsp;&nbsp; If&nbsp; this&nbsp; variable&nbsp; isn't<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; specified,&nbsp; the&nbsp; default&nbsp; path ``:/bin:/usr/bin'' is used.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In addition, certain errors are treated specially.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If permission is denied for a file (the&nbsp; attempted&nbsp; execve<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; returned&nbsp; EACCES), these functions will continue searching<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the rest of the search path.&nbsp; If no other file&nbsp; is&nbsp; found,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; however,&nbsp; they&nbsp; will return with the global variable errno<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set to EACCES.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If the header of a file isn't&nbsp; recognized&nbsp; (the&nbsp; attempted<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; execve returned ENOEXEC), these functions will execute the<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shell with the path of the file&nbsp; as&nbsp; its&nbsp; first&nbsp; argument.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (If this attempt fails, no further searching is done.)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:8.0pt;color:#76923C'>--<br>Wratko HLAVINA<br>Office NCBI Building 45 Floor 4 Room AS13D-121<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 301-402-9730 voice, 301-480-2484 fax<br>Urgent? cc:urgent@hlavina.com <o:p></o:p></span></p><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></body></html>