运行命令行程序的简单方法 C++ - Windows 7
我正在尝试找到一种更简单的方法来测试我的命令行应用程序。它有参数,所以我从命令提示符运行它。我的过程是这样的:
- 构建
- 转到输出
- 打开命令提示符
- 更改目录
- 运行它
必须有一种更简单的方法,不仅可以调试,而且可以在当前文件夹中打开命令提示符。
谢谢您的宝贵时间。
I am trying to find an easier way to test my command line application. It has arguments so I run it from a command prompt. My process is this:
- Build
- Go to the output
- Open command prompt
- Change directory
- Run it
There has to be an easier way not only to debug but to open a command prompt in the current folder.
Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果进入项目属性、调试设置,则可以设置工作目录和参数。如果您始终使用相同的参数,您也可以在该屏幕上输入这些参数。然后只需按 F5 或 Ctrl+F5 即可运行。
在代码末尾设置断点,以防止代码完成后消失。
If you go to the project properties, Debugging settings, you can set the working directory and parameters. If you use the same parameters all of the time, you can enter those in on that screen as well. Then just F5 or Ctrl+F5 to run.
Set a breakpoint at the end of the code to keep it from going away after it is done.
请参阅在 Visual Studio 中使用命令行参数进行调试
或者,你应该能够使用 shell 脚本(或 Python os.system()) 来自动化其中一些步骤。
See Debugging with command-line parameters in Visual Studio
Alternatively, you should be able to use a shell script (or Python os.system()) to automate some of those steps.
要使用资源管理器在当前目录中打开命令提示符,可以按住shift+右键->在此处打开命令窗口。这会节省一点时间。
To open a command prompt in the current directory using explorer, you can shift+right click->Open Command Window Here. That will save a little time.
如果您使用的是 Visual Studio,按 F5 将在调试器中运行代码,而 Ctrl+F5 将正常运行代码。只需记住在末尾包含
cin.get()
语句,否则终端窗口将在您读取输出之前关闭。其他IDE应该也有类似的功能。检查“运行”或“调试”菜单。
编辑:抱歉,没有看到您询问如何使用参数运行它。在 VS 中,项目属性中有调试设置。其中,有一个称为命令参数的字段。当您从 VS 中运行应用程序时,这些将被传递到应用程序。
If you're using Visual Studio, pressing F5 will run the code in the debugger, and Ctrl+F5 will run the code normally. Just remember to include a
cin.get()
statement at the end or the terminal window will close before you can read the output.Other IDEs should have similar functions. Check in the Run or Debug menu.
EDIT: Sorry, didn't see that you're asking about running it with arguments. In VS, in Project Properties there are the Debugging settings. Within that, there is a field called Command Arguments. These will get passed to the application when you run it from within VS.
在调试下的项目属性中,您可以在调试时设置命令行参数(和环境变量),
In project properties under debugging you can set the command line arguments (and environment variables) when debugging,
有一个名为
PowerCommands for Visual Studio 2010
的扩展,可以从工具 -> 中安装。扩展管理器。它包括
打开包含文件夹
和打开命令提示符
功能,这些功能添加到解决方案资源管理器中的右键单击菜单中。There is an extension called
PowerCommands for Visual Studio 2010
that can be installed fromTools -> Extension Manager
. It includes aOpen Containing Folder
andOpen Command Prompt
functionality that gets added to your right-click menu in the Solution Explorer.