B Created: 11 January 2003 Requires: Python 2.x Successfully tested on: ======== ============ ================================================= os.name sys.platform comments ======== ============ ================================================= posix linux2 Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3 PyCrust 0.9.3, Idle 1.0.2 posix linux2 Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2 posix sunos5 SunOS 5.9, Python 2.2, 2.3.2 posix darwin Darwin 7.2.0, Python 2.3 nt win32 Windows Me Python 2.3(EE), Idle 1.0, PyCrust 0.7.2 Python 2.1.1 Idle 0.8 nt win32 Windows 98, Python 2.1.1. Idle 0.8 nt win32 Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests fail i.e. redefining environment variables may not work. FIXED: don't use cygwin echo! Comment: also `cmd /c echo` will not work but redefining environment variables do work. posix cygwin Cygwin 98-4.10, Python 2.3.3(cygming special) nt win32 Windows XP, Python 2.3.3 ======== ============ ================================================= Known bugs: * Tests, that send messages to stderr, fail when executed from MSYS prompt because the messages are lost at some point. )divisionabsolute_importprint_function exec_commandfind_executableN) is_sequencemake_temp_file)logcCst\}}||S)N)rclose)Zfonamer O/opt/alt/python37/lib64/python3.7/site-packages/numpy/distutils/exec_command.pytemp_file_name?s rcCs\tj}tjdkrXtj|\}}|dd}tj||}tj |sXt d|f|S)N)ntdosZPYTHONWZPYTHONz%r is not a file) sys executableosr pathsplitupperreplacejoinisfileAssertionError)Z pythonexeZfdirfnr r r get_pythonexeDs rc Csz||f}y||Stk r$YnXtd||}|dkrPtjdtj}tjdkrdtjj }ndd}| dr|dd }d g}tjd krtj |\}}d d dg} | | kr| }tj |rd g} ndd|tjD} x| D]x}tj||}xd|D]\} || } tj| s&|| } tj| rt| tjrtd| | ||<| SqWqWtd|dS)zTReturn full path of a executable or None. Symbolic links are not followed. zfind_executable(%r)NPATHposixcSs|S)Nr )ar r r _z!find_executable..")rrZos2z.exez.comz.batcSsg|]}tj|qSr )rrabspath).0pr r r nsz#find_executable..zFound executable %szCould not locate executable %s)KeyErrorr debugrenvirongetdefpathr rrealpath startswithsplitextlowerisabsrpathseprislinkraccessX_OKinfowarn) Zexer_cachekeyZorig_exer/suffixesrZextZextra_suffixespathssZf_extr r r rMsF          cCs4td|i}x|D]}tj|||<qW|S)Nz_preserve_environment(%r))r r+rr,r-)namesenvr r r r _preserve_environments  rAcKs2tdx"|D]\}}|p"dtj|<qWdS)Nz_update_environment(...)r%)r r+itemsrr,)r@r valuer r r _update_environments rDcCs6t|dr.y |dStk r*dSXndSdS)zT Returns True if 'stream' supports the file descriptor and allows fileno(). filenoTFN)hasattrrEIOError)streamr r r _supports_filenos rIr%r#c Kshtd|ddd|Df|dkr8tjdk}|dkrJtjdk}tj|}tjt}t dddkrtj tjt }nDtj d rtjd }n*tjt jd }tj |rtj |}||krt|td |ntd |tt|}tf|zt|f||d|} Wd||krXt|td|tf|X| S)a Return (status,output) of executed command. Parameters ---------- command : str A concatenated string of executable and arguments. execute_in : str Before running command ``cd execute_in`` and after ``cd -``. use_shell : {bool, None}, optional If True, execute ``sh -c command``. Default None (True) use_tee : {bool, None}, optional If True use tee. Default None (True) Returns ------- res : str Both stdout and stderr messages. Notes ----- On NT, DOS systems the returned status is correct for external commands. Wild cards will not work for non-posix systems or when use_shell=0. zexec_command(%r,%s),cSsg|] }d|qS)z%s=%rr )r'Zkvr r r r)sz exec_command..Nrirzexec_command.py.rz New cwd: %szRetaining cwd: %s) use_shelluse_teezRestored cwd to %s)r r+rrBrr rr&getcwd__name__dirname__file__rrargvchdirrAlistkeysrD _exec_command) commandZ execute_inrLrMZ _with_pythonr@ZoldcwdZexec_dirZoldenvstr r r rs>            cKs|dkrtjdk}|dkr$tjdk}tjdkrj|rjtjdd}t|rZ|dd|g}n |d|g}d}n&tjdkrt|rdd d |D}|pd}ytj|||tjtj d d }Wnt k rd SX| \}}|dddkr|dd}|r|rt ||j |fS)z0 Internal workhorse for exec_command(). NrZSHELLz/bin/shz-c Frcss|]}t|VqdS)N) _quote_arg)r'argr r r sz _exec_command..T)shellr@stdoutstderrZuniversal_newlines)r%r$ )rr r,r-rr subprocessPopenPIPEZSTDOUTEnvironmentErrorZ communicateprint returncode)rWrLrMr@Zshproctexterrr r r rVs4        rVcCsd|krd|krd|S|S)zB Quote the argument for safe use in a shell command line. r"rYz"%s"r )r[r r r rZ srZ)r%NNr#)NN)__doc__Z __future__rrr__all__rrrbZnumpy.distutils.misc_utilrrZnumpy.distutilsr rrrrArDrIrrVrZr r r r 3s"  3  E *