Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
deleted 60 characters in body
Source Link
Georg Plaz
  • 6k
  • 5
  • 44
  • 66

EDIT: Came back here: it works like a charm with subprocess from python3 and if you are on linux, there is a backport to python2 called subprocess32subprocess32 which does the work quite well

  • SOLVED: I used pexpect and it works

     def cmdlineCall(name, args): child = pexpect.spawn(name, args) # Wait for the end of the output child.expect(pexpect.EOF) out = child.before # we get all the data before the EOF (stderr and stdout) child.close() # that will set the return code for us # signalstatus and existstatus read as the same (for my purpose only) if child.exitstatus is None: returncode = child.signalstatus else: returncode=child.exitstatus return (out,returncode) 

Older solution: I used pexpect and it works

def cmd_line_call(name, args): child = pexpect.spawn(name, args) # Wait for the end of the output child.expect(pexpect.EOF) out = child.before # we get all the data before the EOF (stderr and stdout) child.close() # that will set the return code for us # signalstatus and existstatus read as the same (for my purpose only) if child.exitstatus is None: returncode = child.signalstatus else: returncode = child.exitstatus return (out, returncode) 

PS: a little slower (because it spawnspawns a pseudo tty)

EDIT: Came back here: it works like a charm with subprocess from python3 and if you are on linux, there is a backport to python2 called subprocess32 which does the work quite well

  • SOLVED: I used pexpect and it works

     def cmdlineCall(name, args): child = pexpect.spawn(name, args) # Wait for the end of the output child.expect(pexpect.EOF) out = child.before # we get all the data before the EOF (stderr and stdout) child.close() # that will set the return code for us # signalstatus and existstatus read as the same (for my purpose only) if child.exitstatus is None: returncode = child.signalstatus else: returncode=child.exitstatus return (out,returncode) 

PS: a little slower (because it spawn a pseudo tty)

Came back here: it works like a charm with subprocess from python3 and if you are on linux, there is a backport to python2 called subprocess32 which does work quite well

Older solution: I used pexpect and it works

def cmd_line_call(name, args): child = pexpect.spawn(name, args) # Wait for the end of the output child.expect(pexpect.EOF) out = child.before # we get all the data before the EOF (stderr and stdout) child.close() # that will set the return code for us # signalstatus and existstatus read as the same (for my purpose only) if child.exitstatus is None: returncode = child.signalstatus else: returncode = child.exitstatus return (out, returncode) 

PS: a little slower (because it spawns a pseudo tty)

added 4 characters in body
Source Link
Tic
  • 440
  • 1
  • 5
  • 14

EDIT: Came back here: it works like a charm with subprocess from python3 and if you are on linux, there is a backport to python2 called subprocess32 which does the work quite well

  • SOLVED: I used pexpect and it works

      def cmdlineCall(name, args):   child = pexpect.spawn(name, args)   # Wait for the end of the output   child.expect(pexpect.EOF)   out = child.before # we get all the data before the EOF (stderr and stdout)   child.close() # that will set the return code for us   # signalstatus and existstatus read as the same (for my purpose only)   if child.exitstatus is None:   returncode = child.signalstatus   else:   returncode=child.exitstatus   return (out,returncode) 

PS: a little slower (because it spawn a pseudo tty)

EDIT: Came back here: it works like a charm with subprocess from python3 and if you are on linux, there is a backport to python2 called subprocess32 which does the work quite well

  • SOLVED: I used pexpect and it works

     def cmdlineCall(name, args): child = pexpect.spawn(name, args) # Wait for the end of the output child.expect(pexpect.EOF) out = child.before # we get all the data before the EOF (stderr and stdout) child.close() # that will set the return code for us # signalstatus and existstatus read as the same (for my purpose only) if child.exitstatus is None: returncode = child.signalstatus else: returncode=child.exitstatus return (out,returncode) 

PS: a little slower (because it spawn a pseudo tty)

EDIT: Came back here: it works like a charm with subprocess from python3 and if you are on linux, there is a backport to python2 called subprocess32 which does the work quite well

EDIT: Came back here: it works like a charm with subprocess from python3 and if you are on linux, there is a backport to python2 called subprocess32 which does the work quite well

  • SOLVED: I used pexpect and it works

      def cmdlineCall(name, args):   child = pexpect.spawn(name, args)   # Wait for the end of the output   child.expect(pexpect.EOF)   out = child.before # we get all the data before the EOF (stderr and stdout)   child.close() # that will set the return code for us   # signalstatus and existstatus read as the same (for my purpose only)   if child.exitstatus is None:   returncode = child.signalstatus   else:   returncode=child.exitstatus   return (out,returncode) 

PS: a little slower (because it spawn a pseudo tty)

added 181 characters in body
Source Link
Tic
  • 440
  • 1
  • 5
  • 14
  • SOLVED: I used pexpect and it works

     def cmdlineCall(name, args): child = pexpect.spawn(name, args) # Wait for the end of the output child.expect(pexpect.EOF) out = child.before # we get all the data before the EOF (stderr and stdout) child.close() # that will set the return code for us # signalstatus and existstatus read as the same (for my purpose only) if child.exitstatus is None: returncode = child.signalstatus else: returncode=child.exitstatus return (out,returncode) 

PS: a little slower (because it spawn a pseudo tty)

EDIT: Came back here: it works like a charm with subprocess from python3 and if you are on linux, there is a backport to python2 called subprocess32 which does the work quite well

  • SOLVED: I used pexpect and it works

     def cmdlineCall(name, args): child = pexpect.spawn(name, args) # Wait for the end of the output child.expect(pexpect.EOF) out = child.before # we get all the data before the EOF (stderr and stdout) child.close() # that will set the return code for us # signalstatus and existstatus read as the same (for my purpose only) if child.exitstatus is None: returncode = child.signalstatus else: returncode=child.exitstatus return (out,returncode) 

PS: a little slower (because it spawn a pseudo tty)

  • SOLVED: I used pexpect and it works

     def cmdlineCall(name, args): child = pexpect.spawn(name, args) # Wait for the end of the output child.expect(pexpect.EOF) out = child.before # we get all the data before the EOF (stderr and stdout) child.close() # that will set the return code for us # signalstatus and existstatus read as the same (for my purpose only) if child.exitstatus is None: returncode = child.signalstatus else: returncode=child.exitstatus return (out,returncode) 

PS: a little slower (because it spawn a pseudo tty)

EDIT: Came back here: it works like a charm with subprocess from python3 and if you are on linux, there is a backport to python2 called subprocess32 which does the work quite well

i
Source Link
Tic
  • 440
  • 1
  • 5
  • 14
Loading
Source Link
Tic
  • 440
  • 1
  • 5
  • 14
Loading