add an option to build PyStand as a console based application#9
Merged
Conversation
GUI-based PyStand is not suitable for CLI scripts: - It doesn't redirect stdin, so user can not call `input`; - Using AttachConsole, user must hit ENTER to exit PyStand.exe when it is executed from command line or PowerShell;
Owner
|
我不是特别想加这个命令行功能,因为希望强迫用户不要再 PyStand.int 里写太多东西 ,并依赖 PyStand.exe 进行调试。 更应该先完全独立的调试好你的主程序,比如 sys.path.append(...)
import main
main.main()就行,仅作入口用,实在有错误在 PyStand 里发生,那再看一下 console。再 但是你还在命令行内,随时可以输入新命令。 不过要加命令行我也不反对,表达下我的倾向。
|
Contributor
Author
|
多谢大佬的回复! 其实我是在排查 #7 的时候发现的命令行版本在某些情形下的排错优势的。 Line 304 in c6e45a1 时会输出:
但 GUI 版本里,由于 sys.stdout、sys.stderr 的赋值是出现在这一行代码之后的,因而即使从命令行运行 PyStand.exe,也无法看到这个错误提示信息。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
基于如下几点原因,GUI 版本的 PyStand.exe 不太适合封装一个 Python 命令行脚本(比如:https://github.com/myd7349/Ongoing-Study/blob/master/python/extract_columns.py ):
此外,命令行版本的 PyStand.exe 也更方便在 IDE 中调试的时候及时查看错误输出(比如:init_script 中的错误输出)。
本 PR 中新增一个 CMake option
PYSTAND_CONSOLE_BASED,只需要:即可将 PyStand.exe 编译为一个控制台应用程序。
值得讨论的一些事项:
PYSTAND_CONSOLE_BASED这个名字(抑或定义一个 PYSTAND_CONSOLE,或者 PYSTAND_GUI_BASED,并将 PYSTAND_GUI_BASED 默认为 ON);GetCommandLineW+CommandLineToArgvW(本 PR 尚未这样做);参考: