Hold command prompt window in Visual Studio, when using Command Line Arguments - visual-studio

I need to test my console application with example input data, stored in a file. I want this file to be executed when I start my application in Visual Studio. In normal situation, in command prompt I write: program.exe < input.txt , the program is executed, I get the results and the screen (prompt) waits. I have found in Visual Studio that I can write this: "< input.txt" in Project->Properties->Debug->Command Line Arguments and when I hit F5 I can see that the program gives me the results, but the command window closes immediately. How can I hold this Window? I tried Ctrl+F5, but it doesn't load my input.txt file. Also the application is going to be send to another test system, so I should not write any Console.Read() (ReadLine, Readkey...) methods in the end of the file, because I think this will mess things up. I need answers for this problem for Visual Studio 2010 (2008, 2005) and languages: C/C++, C# if possible.

Just a quick hack if you can't work it out
if (System.Diagnostics.Debugger.IsAttached)
{
Console.WriteLine("Press [ENTER] to finish");
Console.Read();
}

Related

I have a debugging issue with Visual Studio Community 2015

Whenever I am debugging a new program by pressing the "Start without deubgging" button, sometimes it will open up a blank program like this:
I can not close these blank programs at all no matter how many times I try and close it, even with the task manager. And if I try to debug it again, it just opens up another blank program. The only way to fix this program is to either restart or shut my computer, but doing that tedious and I don't want to do that every time this happens. Is there a way to prevent this or at least close the blank programs? Thanks!

How to comfortably monitor variables in a VBscript during development process? (e.g. in a continuously opened command window)

I need to write a huge VBscript to automatically run an application and I'm looking for a way to comfortably monitor what I'm actually doing, in other words, to display the values of some/all variables involved in my script.
I'm used to work with Matlab, where I have a comfortable workspace browser. When I run a Matlab script, all variables, their types and their values are accessible in that workspace and can be checked.
The VBscript I write with Notepad++ (it needs to be a free editor) and the only way I found to display variables was echoing them via wscript and cscript.
I set up the shortcuts.xml with the following line to run my script directly from Notepad++:
<Command name="Run with CScript" Ctrl="yes" Alt="no" Shift="yes" Key="116">cmd /K %windir%\system32\cscript.exe "$(FULL_CURRENT_PATH)"</Command>
In case I include commands in my script like
Wscript.Echo myVar
Wscript.Echo "Hello World!"
and run it with the newly introduced shortcut, a cmd window pops up and displays the value of myVar and "Hello World!".
But the next time I run the script a new window pops up. So my question is:
Is it possible get a continuously opened output window, displaying all echoed values everytime I run a script? I actually want to put the window on a second screen and keep the values from previous runs. So I can enter a line Wscript.Echo something, run, check, enter something else and so on, without fiddling around with a bunch of opened windows.
Alternatively, is there any open-source/free editor which offers an accessible workspace like the one in Matlab?
The open-source editor SciTE offers what I was looking for.
The default settings in vb.properties enable a similar behavior like in Notepad++
command.build.$(file.patterns.wscript)=cscript "$(FilePath)"
command.build.subsystem.$(file.patterns.wscript)=1
One can change it as follows to get the output into the integrated console.
command.go.$(file.patterns.wscript)=cscript.exe //nologo "$(FilePath)"
command.go.subsystem.$(file.patterns.wscript)=0
F5 runs the script and Shift+F5 cleans the output.
Another option is the NppExec Plugin for Notepad++ suggested by #Ansgar Wiechers, which adds a console. The script can be run with cscript.exe /nologo "$(FULL_CURRENT_PATH)" then.
Use a debugger. Start your script with the (meta)option //X. If you are lucky, you already have installed software (MS Office, Visual Studio (Express)) that provides a debugger for VBScript. If not do a bit of research to find an Express version suitable to your OS.
You can almost write native VBScript in the VBA editor, so if you have Excel or whatever you can use this to debug, then go through some steps to convert back to VBScript. That's what I usually do.

How to print something to command window in Visual FoxPro 9?

I am trying to write simple program in Visual FoxPro, I am using built in Help, but cannot find an answer there. There are dozens of samples but they all work with forms, and I just need something like console.out() or printf().
While looking for some samples on internet, found this:
? 2 + 2
This line supposed to print 4, but nothing happens when the program is run from the menu or tool bar.
In the command window, type "set device to screen"
You can create a program, may be called "start.prg" including the line above in the program. This is run everytime Foxpro is started from Desktop.
Click on Tools, Options, File locations, Startup Program,then "modify"
and enter the location of the "start.prg", for example, C:\Program Files\Microsoft Visual Foxpro 9\start.prg
******to print to paper *********************************************
set device to printer
set printer to &&& turn off all open print commands
???" " &&& open printer in raw mode
p_Landscape_On =chr(27)+"&l1O"
p_Landscape_Off =chr(27)+"&l0O"
n_Row=2
#n_Row, 1 say (p_Landscape_On) +(p_Draft)+(p_14inPaper)
n_Row=n_Row+1
******end of printing*****************************
#n_Row,n_Col_fav say (p_Landscape_Off)+(p_12CharPerInch)+p_Portrait)
set printer to
set device to screen
Type this into the Command text box and press Enter. Close all opened tables (if any) in order to see 4.
? is the correct way to display on screen. It will display on the next line of the current main window.
If you are getting no results try SET CONSOLE ON before your ?2+2
Another option, depending on your needs, is to use a WAIT WINDOW, ie WAIT WINDOW 'test'
You can also try ACTIVATE SCREEN prior to printing your text.

Running application in Visual Studio Express

I am coming from XCode and this is probably a stupid question, but after I build my program successfully, I try to click on the Application in the debug folder and the window just closes. How do I run my application that I create?
The above answers are correct, but if your question is simply why your command prompt closes immediately upon your program's termination, you have two options:
Put a breakpoint on your main()'s } before you run.
Use Ctrl+F5, which will add a "Press any key to continue" at the end so you can see all of your program's output, but it will launch the application without attaching the debugger.
You can compile and run the program by pressing F5.
However, if you're talking about non-gui console application which just prints something and exists,
the output window will close right away. If this is the case, you might want to open command prompt (cmd.exe) and run it from there manually, or insert some "wait for keypress" handling, such as getchar().
Otherwise, there might be something wrong with your program :)
Debug --> Run
or
press F5

Output window to file (Visual Studio 2005)

In Visual Studio 2005, how can I save what's written to the output window to a file (I can't change the code writing to the output window, and it writes a lot; I just want to save the output window content to a file)?
"File" -> "SaveOutputAs..." let's you save the contents of the output window to a file, but I imagine you want to redirect the output to a file while debugging? I'm still looking for a way to do that myself..
You can just redirect the output stream in the command line arguments in Visual Studio.
Right click on your project → Properties → Configuration properties → Debugging → Command arguments.
After your arguments, just add:
> outputfile.txt
If you mean the output to the debug/trace window, you can capture this at runtime with DebugView without running Visual Studio.
I just answered a very similar question here. I'm using this method myself to capture, filter and log debug output to a file on Windows Vista 32 bit. I use Visual Studio 2005 and work in C++, so this might help you too.
ATLTrace Tool intercepts the ATLTRACE calls. You can save the output of any process into a file.
Are you developing in .NET? And what is the code used to write to the output window?
In case you are using Trace.WriteLine or Debug.WriteLine you could use a TextWriterFileListener class to write all messages to a file automatically.
If the app runs in a command window, you can use the old DOS redirect command ">" to redirect the output to a file.
For example.
c:\>dir > out.txt
...will redirect the output of the dir command to a file called out.txt. You should be able to do the same with your application.
This will stop the output from going to the console, but you can always go the log file to get you the info you want.

Resources