anyone know how to add command line args in vs2008 - c++

i have a program that runs like so:
a.out 23421232
now if i use a.out it will tell me check params and gives an example and closes.
I am curious if there is a way to add command line args when executing my code in vs2008?

Right click the project in Visual Studio. Click Properties. On the Debugging page, there is a Command Arguments property.

Besides using the VS IDE to add parameters for running the program in the IDE, you can also open a command prompt window (Start | Run | cmd) and run the program the same as in Linux, except the .exe extension is optional:
C:\Windows> cd "\Documents and Settings\Administrator\Applications\MyProject"
C:\Documents and Settings\Administrator\Applications\MyProject> myprogram 23421232

VS doesn't normally produce an executable named a.out like most Unix compilers do. Instead, given an input XXX.cpp, it'll produce an executable named XXX.exe.
Adding command line arguments is done by bringing up the project properties (Alt+F7), selecting "Debugging" and then entering the argument(s) in the "Command Arguments" control. There, you'll add JUST the argument "23421232" (or whatever).

Go into the Project Properties window for your executable project.
Under the "Debug" section, you can specify your command line arguments. These will be used when debugging.

Related

Compile and execute cpp in xcode, and add additional execution instructions, Such as iconv command

Sorry, I'm new to Xcode and not very familiar with it, I use Xcode (command line tool project with external build system) to compile cpp files and automatically execute cpp unix executable files. After the program is compiled (command+R), I set the settings as shown in the screenshot below to automatically execute. Is there any way for me to execute also add additional commands?
Such as iconv.
The following line is what I ultimately want to execute.
./myFile argument1 | iconv -f big5
But my Xcode looks like it's executing only
./myFile argument1
really thanks
On the same place where you setup the build scheme, you can also add a post-build script.
Go to the left of the panel, and expand Build
Select Post-actions
Near the bottom center, click on + -> New Run Script Action
Add script like you would run them in terminal
Note the current directory will not be where the project is built
You can use ${TARGET_BUILD_DIR} macro for the build directory
Note, you want to make sure to select your current project at the Provide build settings from so it can import the correct path macros like TARGET_BUILD_DIR
A screenshot of adding a post-build script:
*Older versions of Xcode might have different GUI, but the idea should be about the same.
Sidenote, ⌘R is really for running the program within Xcode, consider using ⌘B.

C++ in Visual Studio 2015: Manually pass in command line args

In visual studio you can specify in
"Project Properties > Debugging > Command Arguments"
the arguments you want to pass in. But I want to be able to change this manually so I can run different arguments and test my code. Is there a way to open the console and pass in arguments like you normally would in a unix shell?
./myProg arg1 arg2
Having to go into the properties and change every time is annoying.
Thanks!
I'm not sure specifically with how you'd like to open the console, like what the intended result here is. I could interpret this a few ways.
You can run your application from an external command prompt set to the binary directory with any args you want, but the issue is that you would have to attach your debugger if you needed to do debugging. You could switch to console-based debugging or you could introduce a console read in order to attach the debugger.
In later versions of Windows, holding shift and right clicking in Explorer yields an Open command window here option. This makes it quick and easy to open up a command prompt. You can right click a C++ project and Open Folder in File Explorer. This'll get you most of the way there.
If you want, you could specify a special sentinel arg that allows you to interactively populate commandline args within the program. Either that or if there are expected to be args and there are none, you could assume that means interactive mode.
Using cmd /c, you might be able to come up with some really tricky things. Using batch files or all sorts of craziness to populate args. You could combine this with build steps etc. to produce output that batch files read. The sky is the limit.
I don't know specifically what sort of thing you were after, but hopefully this enumerates some things that might be of help.

(VS2010 C++) Execute a command every time the program is run?

The IDE I'm using is VS2010 for writing C++
I want to execute the command cmd C:\utilities\unix\tail.exe -f -n15 $(ProjectDir)Log.txt every time the program I'm coding is run from within the IDE. (This command should open a console to track changes made to the file Log.txt)
There are ways to make a command run every time the program is built, but I can't find a way to make a command run whenever the program itself is run, even if it's already built. Where or how might I be able to set that kind of thing up?
I've tried putting $(TargetPath) & C:\utilities\unix\tail.exe -f -n15 $(ProjectDir)Log.txt into the project's Properties->Debugging->Command (TargetPath is the full name of the debug executable) but VS reads the entire thing as a filename and gets confused.
You can create a file run.cmd for example next to the vcxproj file, which would contain:
%1
C:\utilities\unix\tail.exe -f -n15 %2Log.txt
And then in Properties->Debugging->Command you write:
$(ProjectDir)\run.cmd
and in Command Arguments you write:
"$(TargetPath)" "$(ProjectDir)"
I may have misspelled the macros, but you get the idea: it executes first your program and then whatever you want.
Edit: Unfortunately it works only if you start without debugging (Ctrl+F5), because otherwise the debugger tries to attach to run.cmd and complains that the format is unsupported.

How can I capture the cl.exe command line in Visual Studio 2010?

I have a project that I converted from a makefile that has a source file that expects the command line options from the compiler. For example for when the project was built with gcc if you did program --help it would spit out the gcc command line used to compile the program.
How can I do the same thing in Visual Studio, so that it spits out the cl command line used to compile the program? Basically I want to hit F7 (to build solution) and have the whole thing automated. I can't find a macro for it. Thanks
edit; I mean programatically, so for example I want when I run the program for its output to contain the cl.exe command string that is used. You can see the command line at Configuration Properties > C/C++ > Command Line > All Options but I can't find a macro for it or some way to encapsulate it in a file.
Since VS switched the underlying build system to MsBuild the command line as shown in that dialog is created programatically within VS only. It might not even be the exact command line passed to cl: MsBuild itself invokes CL via a task and as such there is no direct link with what is shown in VS nor is there a way to get the command line out of it.
Anyway, there is no such thing as the command line since each source file might have different options. Furthermore I doubt you want the full commandline including the absolute include paths etc. Nobody is interested in that. Now if you make clever use of the macros from http://msdn.microsoft.com/en-us/library/b0084kay.aspx you can sort of recreate the command line yourself since most options are there:
std::string CompilerCommandLineOptions()
{
std::string cmd;
#ifdef _CHAR_UNSIGNED
cmd += " /J";
#endif
#ifdef __cplusplus_cli
cmd += " /clr";
#endif
#ifdef _CPPRTTI
cmd += " /GR"
#endif
//etc
return cmd;
}
Note: are you sure it's worth the hassle? Is there really somebody interested in the command line? It's not even sufficient to build the project. Why not the linker options as well then?
A .vcxproj is a Visual Studio project in the MSBuild project format. You can build it by running msbuild.exe, devenv.exe, devenv.com, using the Visual Studio GUI or the MSBuild API.
Visual Studio GUI uses the MSBuild API. In doing so, it limits the MSBuild output.
If you want more details, change your user settings in Visual Studio:
Tools > Options > Project and Solutions > Build and Run > two verbosity settings
Detailed will show the cl.exe command lines.
The closest thing which I came across cl command line which msuild executes is "hacking" the rsp file used while calling cl.exe.
Using Override compiler solution, I changed ClCompile ToolExe to custom mycl.bat script and this script received an argument which was #tmp-1234xxx.rsp file. This rsp file contained whole command line except cl.exe path, something like -
rsp file
/P /DDEBUG Source.cpp
Then after making desired changes in the rsp file by calling a separate bash script which were very minor for me, I called cl.exe with contents of my rsp file. So, whenever user hits the build button, this script executes.
mycl.bat script
#echo off
SET PATH=%PATH%;/usr/bin //to call cygwin bash
set parameter=%1
set parameter=%parameter:~1% //to remove # in the beginning
c:/cygwin/bin/bash process.sh %parameter%
process.sh
iconv -f UCS-2 -t UTF-8 <$1 >$1.conv //file converted to UTF-8, else bash wasn't handling it well
contents=`cat $1.conv`
#Processing on file contents here
path/to/cl.exe $(contents)
Very nasty solution, but it worked for my use case. I wanted to change the names of the file on the go based on some logic.
The problem I faced is Visual Studio uses tlogs written by CL Task to check while file needs to to be rebuilt on incremental build and my target's tlogs files were not enough. There were tlogs of every command in batch and bash scripts but not for whole target. So, it was building whole thing on incremental builds also.

IAR - Adding pre-build command to delete an object file

In IAR embedded workbench IDE, I need to force the compilation of a file, every time I build the project (in order to recompile __DATE__ and __TIME__).
So I need to "touch" that file (i.e., delete the corresponding object file).
I went into the project options --> C/C++ Compiler --> Extra Options --> Use command line options.
In there, I entered a shell command for deleting that file, but without luck.
I tried several different ways of doing it, including to call a batch file.
Examples:
del "$OBJ_DIR$\mng_version.o"
cmd /c "del "$OBJ_DIR$\mng_version.o""
pre_build.bat
None of these worked.
Does anybody have any idea how to do this?
I use
Project options -> Build Actions
and enter a command into the Pre-build command line. This can be a batch file invocation. I have a utility that increments a build number declaration in a version file that is then re-compiled on every build.
This is the same on the MSP-430, ARM and Atmel AVR-32 versions of the IAR toolset.