Windows: Can the return value of a process running C++ code be accessed if you don't run from command line? - windows

I know that you can access the return value of the process using the command line or by having one process create and run the other. However, if I just make an *.exe and double click it, does the return value go anywhere that I can access? If so, where? Could I change any settings so that, if my process returns EXIT_FAILURE, Windows will handle things differently than if it returns EXIT_SUCCESS?

No, I don't think anything retains the exit value of a process started in that way. When you double click on a shortcut or executable, Explorer creates the process and then immediately closes the handles because it no longer cares what happens.
You could write a program that calls OpenProcess on the process of interest while it's running. (It would have to have a way to discover the process ID before the process exits.) OpenProcess will give you a handle to the process. The program could then wait on that handle. When the process exits, the program could use the handle to retrieve the status code and do whatever it is you want it to do.

Related

Action cannot be completed because another process is using the file

Not sure whether I have the message above exactly correct but I run into this often. I try to use Windows to delete a directory or a file and it tells me I can't because the file is in use by another program. It doesn't say what process is using it.
Sometimes it is clear what is using it, but other times it is not. I open the Task manager and go through all the processes but nothing stands out.
Is there a way to determine what has a file open, and a solution (other than rebooting)?
I suppose most of the time it may be Eclipse related but certainly not all of the time.
I use Process Explorer
Ever wondered which program has a particular file or directory open?
Now you can find out. Process Explorer shows you information about
which handles and DLLs processes have opened or loaded.
You can add the column like shown below (Window Title) and it should help you find the file you are looking for, and what is using it:
If you end up choosing to use this program instead of Task Manager, there is an option for that which will open this instead of Task Manager:
If you decide to "Replace Task Manager" and ever get stuck where you cannot 'undo' what you've done (Meaning, "The original Task Manager will no longer open")... You can modify the registry listed here and delete the Debugger entry. (In this example, I have this path to a network drive).
I had this problem in Excel, where some files would be active, but not visible to me, either on my screen or in the task manager. The way I solved it was to use the command prompt to kill the task:
Open command prompt (type cmd in windows search at the bottom left of your screen)
Type "tasklist"
Find the task you want to terminate (for me it was EXCEL.EXE)
End the task by either using the image name (type "taskkill /im EXCEL.EXE", or whatever program you want to end. This will kill all tasks with that image name) or using the ID (i.e. "taskill /pid 1234, or whatever ID the program has. This will kill that specific task)

How to close cmd after LabVIEW code executes

When I am running batch file through LabVIEW by using System Exec.vi, two cmd windows are appearing. The second one executes command of the batch file and closes after that, while the first one doesn't close. I have tried to use this solution, but it doesn't work. Is there any way to close that first cmd ?
P.S. If I run batch file not through LabVIEW, but just by double clicking on it, two cmd windows close after execution
It's hard to tell, but I think you've misunderstood the directions given at that link. The batch file should contain the executable and its options, but you just pass the batch file to the System Exec VI. I'm guessing what's happening here is the batch file is getting called twice, and some process that the first call depends on is getting hijacked by the second call, so that when the process ends, the second call gets notified and stops itself, but the first call is left hanging. Or something like that.

Giving the user some information on the run status of my program

I made a simple GUI for my Racket batch data processing program that accepts a user specified input file and writes to a user specified output file. Once the user has specified those files, all they have to do is click a "Run" button. The program works, but the GUI becomes unresponsive while running the batch processing logic. Since it can take a long time to finish, I want to give the user some assurance that it hasn't crashed. How can I avoid this unresponsiveness (at least the frozen window part)?
Run the batch processing in a thread.
See Racket docs on thread

process with different name on windows

I have a process on windows, lets call it DDD.exe .
That process runs several times parallel. I open the task manager. I would like to change the name of the process that runs that it will contained also a number.
For instance: DDD1.exe , DDD2.exe etc' .
Can I do that ?
Thanks
If all you want is to differentiate between the instances, it's already there, in the process's PID column.
That field is the file name of the executable. The only way to change it is to make copies of the executable with different names. I don't imagine you want to do that.
I personally use Process Explorer as my task manager. When you hover over an entry in Process explorer, a hint window is displayed containing the command line passed to the process. You could make use of this feature if you passed a benign ID parameter when you created each process.

My Ruby files don't run correctly

When i click on a .rb file to run it a CMD window pops up for a brief second and then closes again. This is probably a really nooby question thats easily fixed but i've looked everywhere for help. But like i said it pops up for a brief second and i THINK while its up its executing the code but when the codes done it closes so i don't know if i'm making mistakes in code or other important things like that.
Run the program through the command prompt (CMD), that way you can see the result, otherwise the window closes when the program exits.
Alternatively, you can prevent the program from exiting by putting some sort of blocking instruction at the end of the script, such that the program waits for user input before exiting.
Press Windows_Key+R and then type CMD. Browse to the location of the file and then type ruby your_ruby_file.rb. The program is running, but Windows automatically closes the window upon completion of the command.
To get Windows to run your *.rb files through Ruby when you click on them in the UI, you have to associate the .rb extension with the ruby.exe executable. Such an association is called a "Windows File Association." Here's a Microsoft Knowledge Base article that'll tell you how to create such a thing.
http://support.microsoft.com/kb/307859

Resources