##// END OF EJS Templates
util: add public isstdin/isstdout() functions
Yuya Nishihara -
r36811:eca1051e default
parent child Browse files
Show More
@@ -1430,13 +1430,19 b' def _sethgexecutable(path):'
1430 1430 global _hgexecutable
1431 1431 _hgexecutable = path
1432 1432
1433 def _isstdout(f):
1433 def _testfileno(f, stdf):
1434 1434 fileno = getattr(f, 'fileno', None)
1435 1435 try:
1436 return fileno and fileno() == sys.__stdout__.fileno()
1436 return fileno and fileno() == stdf.fileno()
1437 1437 except io.UnsupportedOperation:
1438 1438 return False # fileno() raised UnsupportedOperation
1439 1439
1440 def isstdin(f):
1441 return _testfileno(f, sys.__stdin__)
1442
1443 def isstdout(f):
1444 return _testfileno(f, sys.__stdout__)
1445
1440 1446 def shellenviron(environ=None):
1441 1447 """return environ with optional override, useful for shelling out"""
1442 1448 def py2shell(val):
@@ -1464,7 +1470,7 b' def system(cmd, environ=None, cwd=None, '
1464 1470 pass
1465 1471 cmd = quotecommand(cmd)
1466 1472 env = shellenviron(environ)
1467 if out is None or _isstdout(out):
1473 if out is None or isstdout(out):
1468 1474 rc = subprocess.call(cmd, shell=True, close_fds=closefds,
1469 1475 env=env, cwd=cwd)
1470 1476 else:
General Comments 0
You need to be logged in to leave comments. Login now