How does a program know it's launched from xcode? [duplicate] - xcode

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Detecting if iOS app is run in debugger
I want to add some special handling code when my program is launched from Xcode Debugger (vs. directly launched from simulator or from device). When Xcode launches a program to debug, will it set an enviroment variable?

Simplest approach is to edit your debug scheme to pass a command line type argument, and detect it in main().

Related

Have VC++ executable automatically load debugger [duplicate]

This question already has answers here:
debugging a process spawned with CreateProcess in Visual Studio
(3 answers)
Closed 7 years ago.
I have a program running which loads up a separate program to do some work for it. That separate program is run from the first, using Process.Start() and I need it to load into the Visual Studio debugger to single step through it.
Unfortunately, though I can run the first program in a debugger session, it still starts the second as a "proper" process. I need to have this second program open up in a debugger session. Normally I would just attach a debugger to the process once it's started but, in this case, I need it to breakpoint very early on (in the CInitDialog() function) and, as fast as I am, I can't outrun the code in this case.
A solution I found right here on Stack Overflow said to use Debugger.Launch() but that appears to be specific to C#.
I also thought of trying to cause a crash in the code (such as with a null pointer reference) to load up the debugger but I suspect this would mean single stepping would then be unavailable to me.
How can I do this?
Visual C++ has a similar feature to the C# Debugger.Launch(), it's called DebugBreak(). This actually breaks the application and it will present you with a dialog box asking how you want to handle it:
If you select Debug the program at that point, it will then ask you whether you want to do it in a new Visual Studio session or an existing one. I tend to have the solution already open so I can effectively attach to that one - opening a new instance gives you just the file rather than the entire solution.
So you can simply insert that call in your code where you want to break, and allow the first program to run it as per normal. The second program will start up and break where you've placed the statement and you can then single-step and do all the other wondrous things a debugger allows.

What version is Windows, really? [duplicate]

This question already has answers here:
How to detect true Windows version?
(9 answers)
Closed 7 years ago.
It appears that the version info functions in the Win32 API that I know and love have changed their behavior. GetVersionEx now return what the program's manifest is set for, not the actual version.
The new function IsWindows10OrGreater seems pointless since it is only available on windows 10 or greater, so if the program includes it and successfully links it will always return TRUE.
But, in an installer or similar program, how does it determine whether the current environment really is Windows 10 or greater? It needs this to know what to download or which options to set up for other programs.
Your premise is false. The IsWindows10OrGreater function is a macro, so provided you are using a suitably recent version of the SDK the compiled program will work on all currently supported versions of Windows. (As well as Windows XP and I think even Windows 2000.)
(Of course, this mistake is understandable, since the documentation is wrong.)
Note that the program's manifest must still indicate that it supports Windows 10 in order for the macro to work.

Setting global environment variables in windows programatically [duplicate]

This question already has answers here:
How to set a variable for the current OS session only
(3 answers)
Closed 7 years ago.
As i am frequently moving desktop, I use a lot of portable apps.
I would, however like to alter/add global environment variables programtaically
on startup so that it is available to all consoles and windows in general.
Preferably It should work by running a script.
As the computer may be used later by another person the settings and variables must disappear when rebooted or powerloss occours.
Examples:
I would like to add imagemagick to the PATH on startup
Add to global CLASSPATH on startup.
Any surgestions?
Just set the traditional way. Go to the System Applet, set your user variables.

How can Visual Studio be set to debug a program as soon as that program is launched? [duplicate]

This question already has answers here:
Debugging with command-line parameters in Visual Studio
(13 answers)
Closed 8 years ago.
I am debugging an application someone else wrote which runs as a Windows Service unless it is started from the Console and passed parameters. I would like to start this program from the Console, including some parameters, and then step into the debugger. I'm not sure how to do this since before I execute the command to start it, there is no process to attach to, and once I execute the command, it's too late to catch it (errors begin almost instantly). I'm trying to figure out if there's a way in Visual Studio to set up the debugger to attach to a process before it's actually running (or perhaps something effectively similar, given the description of my problem).
I have a breakpoint on the very first line of Program.Main and I'm essentially trying to figure out how I can launch the application from the Command Prompt and then immediately hit my breakpoint. Is this even possible?
I'm running VS 2013 on Windows Server 2012 Datacenter, by the way.
I think that you don't need to run this program from console - just run (start debugging) it with parameters. Here there is similar question, it should solve you problem. Note that if for some reason my advice is not a good solution for you, you can use solution from second answer (from link) - it's exactly what you are asking for.

Determine if cocoa app was started by the user or a cron/launchd job [duplicate]

This question already has an answer here:
Determine if WindowServer is available?
(1 answer)
Closed 8 years ago.
Is there a way for a Cocoa application to tell if it's being run interactively or from something like cron? Basically I want to have the GUI appear if it's a person running the command, but if it's being called from something like cron, then I don't want the GUI to show.
You can use launchctl list command.
With no arguments, list all of the jobs loaded into launchd
Sounds like you are looking for the isatty function (which is probably what perl's -t test uses).
if (isatty(0)) {
// standard input is a “tty” hence I should run interactively
}

Resources