New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error using run() on Windows - for eg run("cmd /c dir") [fixed] #46
Comments
Hi CK, thanks for raising this! May need your help to test because I don't have access to a Windows laptop now. Issues #45 #46 should be related to the same cause. The best practice for running commands from Python using subprocess requires using the exit 0 to be always appended. This is to capture error messages if the command results in error - Below shows a replication case if exit 0 is not appended and what happens if appended. When it is not appended as part of the command, if the command returns error it will raise a Python exception with error code instead of showing the error message which is more meaningful for debugging.
PS - in above example, I disabled appending in run() in order to test the effect. Will dig further. There may not be a solution or the solution could be not appending for echo commands. For the cmd error, looks like it is some other cause. |
For echo on macOS, it looks alright with appending exit 0.
|
On macOS, the ; works in echo as a delimiter for next command. From your above example, it looks like for Windows, the ; is not recognised by echo as a delimiter. Thus the
|
Solution may be to use https://stackoverflow.com/questions/8055371/how-do-i-run-two-commands-in-one-line-in-windows-cmd |
The issue should have the same root cause at #45 - probably the ; gets interpreted as part of the command resulting in the error message, will check on this when I borrow a Windows laptop. |
Going to update run() to below, tested ok on Windows. Will test on macOS and Linux before patching - def run(command_to_run = None):
if command_to_run is None or command_to_run == '':
print('[TAGUI][ERROR] - command(s) missing for run()')
return ''
else:
if platform.system() == 'Windows':
command_delimiter = ' & '
else:
command_delimiter = '; '
return _py23_decode(subprocess.check_output(
command_to_run + command_delimiter + 'exit 0',
stderr=subprocess.STDOUT,
shell=True)) |
The run() function does not work correctly on Windows. The root cause is semi-colon is not approrpriate as delimiter to combine with exit 0 command (for retrieving error output without triggering exception). This fix uses ; for Linux and macOS and & as the delimiter in Windows environment. More details in #46.
This is now fixed in v1.10 - to upgrade, using Thank you very much @ck81 for spotting this and raising this issue! |
Hi Ken, Just downloaded the latest version. Yes, the following now run's perfectly ok on windows 10 now. run_result = t.run("cmd /c dir")
print("run_result) Thanks for the fix! |
Thanks CK for your update! I appreciate very much that you spotted this and feedback. |
Hi Ken,
Tried to run a DOS command using your suggestion in: aisingapore/TagUI#473
The following works in TagUI:
In TagUI-Python on windows 10:
The above will give the error message:
The text was updated successfully, but these errors were encountered: