|
It can't. It's an indpendent process that doesn't get any information about how or who launched it.
The only way I know of, and probably going to be the easiest, is to write the launched application to take a command line parameter that is passed to it by the launching app.
Whoops. Just went back and reread the question. Since CMD was the app you launched, it doesn't return until the user types EXIT in the CMD window.
If you want to launch application.exe, you can just launch that instead. If you need results from it, you can redirect the StandardIn and StandardOut streams to handlers in your code so you can interact with it.
|
|
|
|
|
Dave:
Thanks! Your answer at least saves me time to make further futile effort.
Could you please elaborate your suggested solution because I am unfamiliar with it? I appreciate your help.
Sheng
|
|
|
|
|
What?? The solution is to run the application.exe instead of launching cmd.exe.
|
|
|
|
|
Do you mean something like this?
if ( Interactive )
{
pr.WaitForExit() ;
}
else
{
while ( !pr.HasExited )
{
this.DoPutOutput ( pr.StandardOutput.ReadLine() ) ;
}
this.DoPutOutput ( pr.StandardOutput.ReadToEnd() ) ;
}
result = pr.ExitCode ;
|
|
|
|
|
pr.WaitForExit() is waiting for cmd.exe to end, not waiting for the application.exe which is run from command line (cmd.exe). application.exe is started from cmd.exe, but runs in a seperate process.
Sheng
|
|
|
|
|
If you start cmd with the arguments /C application.exe , then the cmd process itself will run your app then exit, so you can wait on your proc (cmd) to terminate.
Open a command prompt and enter cmd /? to see other options.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
|
Why don't you do
proc.StartInfo.FileName = "application.exe";
...
proc.Start();
proc.WaitForExit();
int hResult = proc.ExitCode;
|
|
|
|
|
application.exe is a command-line application. It can run only in command line.
"
proc.StartInfo.FileName = "application.exe"
proc.Start()
"
will not start the program.
Sheng
|
|
|
|
|
You should be shelling application.exe, not cmd.exe, unless there's a good reason to do that (I can't think of one).
You can either use WaitForExit, if you want to wait synchronously for a short process, or you can use the Exited event to be notified when a longer process finishes. You need to set EnableRaisingEvents[^] to do it that way (but you probably already have that if you're listening for stdout).
|
|
|
|
|
I tested Peter-in-2780's answer. It works.
Sheng
|
|
|
|
|
Why are you running cmd.exe just to run application.exe. Since your code didn't start the application.exe process, you can't know when it terminates unless you enumerate running processes on the system. The best approach is to skip cmd.exe altogether, and simply run application.exe instead, and make all of the appropriate property settings in the Process object to determine when application.exe actually terminates.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
The problem is that application.exe is a command-line program. It is unable to run directly by Process.StartInfo.FileName = "application.exe". It has to have command line first and then start to run from command line. Peter-in-2780's answer works. Thanks!
Sheng
|
|
|
|
|
Hi all,
Repository[^] pattern with Unit of Work[^] and Dependency Injection, seem to be a universaly accepted solution for ASP.NET + EF applications. There are still some minor questions that I would like to ask here.
Consider the following method from a generic IRepository interface:
public IQueryable<T> Get<T>() where T : class
{
return Set<T>();
}
I wonder, is it a good practice in reveling IQueryable interface to the callers. This means that the calling method can add filters/paggin/sorting, but at the same time the repository itself becomes not unit testable (you cant rely anymore on what the repository will actually return). The caller can even add a non-translatable predicate that will break at runtime. So, is it a good practice in hiding IQueryable interface from the caller, and defining IEnumerable interface instead?
Also, I wonder how do you perform integration tests on repositories? Do you use SQL CE4 , full SQL Server , or just Fake objects on DbContext ?
Appreciate your response,
With regards
modified 1-Mar-12 17:45pm.
|
|
|
|
|
I have no idea, but...
Did you forget to encode your < and > ? He's fixed it.
modified 1-Mar-12 19:34pm.
|
|
|
|
|
I have a program that uses WIA to take and transfer images off of my Nikon D40x. Now I want to add the ability to check battery status on the camera. But have not found a way to do it or if it is even possible. Does anyone have any advise on this?
|
|
|
|
|
Not through WIA it's not.
You'd have to get the Nikon SDK to talk to the camera. I believe you can get that from here[^].
|
|
|
|
|
There has got to be a way. I know there is cont set in WIA for battery status level. Not sure how to use them. And when I plug the camera into the computer, windows uses WIA to communicate with the camera and shows the battery status on the device window.
Have been doing Google searches for hours without any results. How do you pull the properties of the camera through WIA. Such as ISO, shutter speed, etc?
|
|
|
|
|
Icarii wrote: There has got to be a way.
Well, I suppose you don't HAVE to believe Dave...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
By the way I already have the Nikon SDK and it is horrible. Has not been update since 2004.
|
|
|
|
|
Yeah, well I've used the Canon SDK and it was easier to get that kind of stuff using that than trying to figure out WIA's generic for everything way to do it.
|
|
|
|
|
Dave, thank for your replies.
I got it to work using C# and WIA. Here is the code.
private void BatteryWIAStatus()
{
if (camera != null)
{
camera.ExecuteCommand(WIA.CommandID.wiaCommandSynchronize);
try
{
foreach (WIA.Property i in camera.Properties)
{
if (i.Name == "Battery Status")
{
string bStat = i.get_Value().ToString();
lblBattery.Text = "Battery " + bStat + "%";
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error has occurred!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
I put the Synchronize command in to update the status as it appears the battery status is cached. Still testing that part.
|
|
|
|
|
Hello All,
I want to find the query for Total Mail Box Size in Exchange Server 2007. I have implemented this earlier in Exchange Server 2003 with WMI using following Query. select Size from Exchange_Mailbox where Size >= 0. I have googled for it and saw lot of scripts, But I hope I can implement it in a single line query like this using powershell. Can someone shed some light for an easier solution?
Thanks in advance...
Regards
Sebastian
|
|
|
|
|
Sorry, there is no single query. You have to enumerate through the folders of the mailbox and get the total size for each, then add them all up.
|
|
|
|
|
I have this base class:
public abstract class _ViewModelBase : ViewModelBase
{
public _ViewModelBase()
{
RegisterMessaging();
SetupViewModel();
}
protected abstract void RegisterMessaging();
protected abstract void SetupViewModel();
}
It is subclassed into
public abstract class _DataViewModelBase : _ViewModelBase
{
public _EntityBase DataEntity { get; set; }
public _DataViewModelBase(_EntityBase Entity)
: base()
{
DataEntity = Entity;
}
}
In _DataViewModelBase how do I store the DataEntity parameter value to the DataEntity field before :base is called?
Everything makes sense in someone's mind
|
|
|
|