Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to execute a remote command in a web application

Status
Not open for further replies.

BearPalm

Programmer
Oct 20, 2004
6
CA
Hello, I have a problem in executing command line
from a web application. When clicking button "submit",
I can see the command process in "task manager", however,
the process seems hang-up and no any output results.
Why the same code can run in windows application, but
failed in web application?
Can anybody help me?
Thank you.

here is my code

-------------------------------------------------
private void BtnSubmit_Click(object sender, System.EventArgs e)
{
int ret;
ret = ExecuteExternalCommand(mycmd.bat, 10000);
}

public int ExecuteExternalCommand(string cmd_string, int waiting_time)
{
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo(@cmd_string);
psi.RedirectStandardOutput = true;
psi.CreateNoWindow = false;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
System.Diagnostics.Process listFiles;
listFiles = System.Diagnostics.Process.Start(psi);

System.IO.StreamReader AppOutput=listFiles.StandardOutput;
listFiles.WaitForExit(waiting_time);
if(listFiles.HasExited)
{
return 0;
}
else
{
listFiles.Close();
}
return 1;
}
 
if you use that command from a web app, the mycmd.bat would have to be situated on the webserver and also in the same dir as the dll generated by the app. also it would need rights to run since this is ran on the server.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 

My batch command was really not located at the directory
generated by the web application. However, using your
method moving the batch command to web directory, nothing
can be improved.
Anyway, thank you so much. I will try it again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top