0

I have created a GUI that runs a command in Linux Terminal.

EXAMPLE=> -n 20 -id 15 -domain square(10,20) -dim 2 -o execution -format geo,tess

This command is for the execution of a code for package. And when it executes a series of outputs undergo in the Linux terminal. The output is either successful and the output is generated or an error occurs due to a dump error or bad argument.

Examples of Terminal Outputs:

Error : matheval failed to process the expression. The expression syntax is probably incorrect. This may also be caused by an unproper matheval installation (expression = 1 -ori fibre(,,)). Aborted (core dumped)

Another Error

Error : Bad arguments! Aborted (core dumped)

What i am trying to do is return this error back into the GUI as either a MessageBox and/or update the bottom Status bar of the GUI with the error.

I am not familiar with the wx and subprocess modules, but my research so far has failed to find a solution.

I am running Python 2.7 and using Tkinter.

Aly Abdelaziz
  • 292
  • 4
  • 24
  • If your trouble is with Tk, [this might help](http://stackoverflow.com/questions/17280637/tkinter-messagebox-without-window). – Brian McFarland Mar 07 '16 at 19:25
  • If your trouble is with capturing `stderr` of your "Linux Terminal" command, you probably need `subprocess.Popen()` with `stderr=subprocess.PIPE`. For example, try: `p = subprocess.Popen( '/bin/cat /bad_path'.split(), stderr=subprocess.PIPE)` followed by `sout, serr=p.communicate()`. – Brian McFarland Mar 07 '16 at 19:29
  • @BrianMcFarland thank you for that. I understand that i need to pass the command i am using in the Popen > p = subprocess.Popen( ['neper', '-T', '-format', output_form, '-n', n, '-id', id, '-dim', dim, reg], stdout=subprocess.PIPE) because this seems to create an error in the Terminal, although the command syntax is correct. – Aly Abdelaziz Mar 08 '16 at 01:14
  • A Python error or an error from the program? If its a Python exception, post it here and maybe somebody can help. If its an error generated by your program, `neper`, then there's likely not much that can be done w/o knowing the program. – Brian McFarland Mar 08 '16 at 14:43
  • @BrianMcFarland the error is generated by the program. The weird part is when you use the Popen command, the execution of the program starts and then aborted due to an error. However, same command but using the os.system OR the terminal executes successfully. I will give it one more shot before i post it here. Thanks for the help, really appreciated :). – Aly Abdelaziz Mar 08 '16 at 14:49

1 Answers1

0

This seems to get the work done.

        # Create a string and pass variables 
        neper_exec = "neper -T -n %s -id %s -format %s -o %s -dim %s -domain %s " % (n, id, output_form, o, dim, domain)
        # Execute the subporcess using the variable
        p = subprocess.Popen(neper_exec, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # when shell is dropped Linux gives and error

Thanks to @BrianMcFarland for guidance on the subprocess command.

Aly Abdelaziz
  • 292
  • 4
  • 24