472,959 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,959 software developers and data experts.

How can i run a batch file asp.net

Hi every one,

I am trying to run a batch file using my asp.net application.

I am using the Process class to run the batch file. When I run my web
application, In the task manager, i could see cmd.exe with ASPNET as a
user. But nothing happens. It can't execute the batch file.

This is the code i am using to run the batch file:

private void Request()

{

string Fichier=Server.MapPath("")+"\\SearchEng\\request.b at";

Process proc=new System.Diagnostics.Process();

proc.StartInfo.WindowStyle=ProcessWindowStyle.Maxi mized;
proc.StartInfo.WorkingDirectory=Server.MapPath("") +"\\SearchEng\\";

proc.StartInfo.FileName=Fichier;

try

{

proc.Start();
proc.WaitForExit();

proc.Close();

}
catch(Exception ex)

{

this.lblerror.Text=ex.Message;

}

}

************************************************** ******************

string Fichier=Server.MapPath("")+\\SearchEng\\request.ba t;
Response.Write(Fichier)

It does return the physical path of the file starting from
C:\myApplication\SearchEng\request.bat.

But if don't run the file from the physical path (example : if fichier
= SearchEng\request.bat) it does give me an error : The system cannot
find the file specified.

I did another test: When i manually click on the request.bat file it
does execute and returns me the right answers.

This is what i get on my dos screen when i run the bat file with my
code.

C:\myApplication\SearchEng>set
path="C:\myApplication\SearchEng";C:\WINDOWS\syste m32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program
Files\ATI Technologies\ATI Control Panel;C:\Program Files\Microsoft SQL
Server\80\Tools\BINN;C:\bin C:\myApplication\SearchEng>java -jar
"C:\myApplication\SearchEng\SearchEngine.jar" GOOGLE/EPS/ gps IPSearch
Version 1.22 All rights reserved 2005 my company Researche in
progress ...... Error Results are saved in the Results.xml

You can see research is in progress. I think the Process end before the
SearchEngine.jar finishes executing.

But when i run it manually i don't no error, Very strange

I tried this proc.WaitForExit(900000) or proc.WaitForExit() but still
ended without success.

The content of my batch file is :
set path="C:\myApplication\SearchEng";%path%
java -jar "C:\myApplication\SearchEng\SearchEngine.jar" GOOGLE/EPS/ gps

This batch file execute : SearchEngine.jar in dos then it saves the
results in Results.xml

Then i get the results then list them in a treeview.

Have a wonderfull day.

Feb 3 '06 #1
3 4322
As a start, when you run a process from asp.net it cant invoke windows
unless you run the asp.net account under a specific domain user profile.
Get rid of your windowstyle option and see if it runs.

You have to get in the mindset of the webserver, no windows, no desktop, few
rights.

--
Regards

John Timney
Microsoft MVP

<em******@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi every one,

I am trying to run a batch file using my asp.net application.

I am using the Process class to run the batch file. When I run my web
application, In the task manager, i could see cmd.exe with ASPNET as a
user. But nothing happens. It can't execute the batch file.

This is the code i am using to run the batch file:

private void Request()

{

string Fichier=Server.MapPath("")+"\\SearchEng\\request.b at";

Process proc=new System.Diagnostics.Process();

proc.StartInfo.WindowStyle=ProcessWindowStyle.Maxi mized;
proc.StartInfo.WorkingDirectory=Server.MapPath("") +"\\SearchEng\\";

proc.StartInfo.FileName=Fichier;

try

{

proc.Start();
proc.WaitForExit();

proc.Close();

}
catch(Exception ex)

{

this.lblerror.Text=ex.Message;

}

}

************************************************** ******************

string Fichier=Server.MapPath("")+\\SearchEng\\request.ba t;
Response.Write(Fichier)

It does return the physical path of the file starting from
C:\myApplication\SearchEng\request.bat.

But if don't run the file from the physical path (example : if fichier
= SearchEng\request.bat) it does give me an error : The system cannot
find the file specified.

I did another test: When i manually click on the request.bat file it
does execute and returns me the right answers.

This is what i get on my dos screen when i run the bat file with my
code.

C:\myApplication\SearchEng>set
path="C:\myApplication\SearchEng";C:\WINDOWS\syste m32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program
Files\ATI Technologies\ATI Control Panel;C:\Program Files\Microsoft SQL
Server\80\Tools\BINN;C:\bin C:\myApplication\SearchEng>java -jar
"C:\myApplication\SearchEng\SearchEngine.jar" GOOGLE/EPS/ gps IPSearch
Version 1.22 All rights reserved 2005 my company Researche in
progress ...... Error Results are saved in the Results.xml

You can see research is in progress. I think the Process end before the
SearchEngine.jar finishes executing.

But when i run it manually i don't no error, Very strange

I tried this proc.WaitForExit(900000) or proc.WaitForExit() but still
ended without success.

The content of my batch file is :
set path="C:\myApplication\SearchEng";%path%
java -jar "C:\myApplication\SearchEng\SearchEngine.jar" GOOGLE/EPS/ gps

This batch file execute : SearchEngine.jar in dos then it saves the
results in Results.xml

Then i get the results then list them in a treeview.

Have a wonderfull day.
Feb 3 '06 #2
Salut,

First, I'd change Request() to something else. In ASP.NET you're likely
referring to the Request object.

I was playing with this code by Brendan Tompkins that might help do what you
want:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
ARequest();
}
private void ARequest()
{
// Credit to Brendan Tompkins
//http://codebetter.com/blogs/brendan.tompkins/archive/2004/05/13/13484.aspx
// Get the full file path
string strFilePath = Server.MapPath("request.bat");

// Create the ProcessInfo object
System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.WorkingDirectory = Server.MapPath("");

// Start the process
System.Diagnostics.Process proc =
System.Diagnostics.Process.Start(psi);

// Open the batch file for reading
System.IO.StreamReader strm = System.IO.File.OpenText(strFilePath);

// Attach the output for reading
System.IO.StreamReader sOut = proc.StandardOutput;

// Attach the in for writing
System.IO.StreamWriter sIn = proc.StandardInput;

// Write each line of the batch file to standard input
while (strm.Peek() != -1)
{
sIn.WriteLine(strm.ReadLine());
}
strm.Close();
// Exit CMD.EXE
string stEchoFmt = "# {0} run successfully. Exiting";
sIn.WriteLine(String.Format(stEchoFmt, strFilePath));
sIn.WriteLine("EXIT");
// Close the process
proc.Close();
// Read the sOut to a string.
string results = sOut.ReadToEnd().Trim();
// Close the io Streams;
sIn.Close();
sOut.Close();

// Write out the results.
string fmtStdOut = "<code>{0}</code>";
lblerror.Text = String.Format(fmtStdOut,
results.Replace(System.Environment.NewLine, "<br>"));
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Run Batch</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label id="lblerror" runat="server"></asp:label></div>
</form>
</body>
</html>

<em******@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi every one,

I am trying to run a batch file using my asp.net application.

I am using the Process class to run the batch file. When I run my web
application, In the task manager, i could see cmd.exe with ASPNET as a
user. But nothing happens. It can't execute the batch file.

This is the code i am using to run the batch file:

private void Request()

{

string Fichier=Server.MapPath("")+"\\SearchEng\\request.b at";

Process proc=new System.Diagnostics.Process();

proc.StartInfo.WindowStyle=ProcessWindowStyle.Maxi mized;
proc.StartInfo.WorkingDirectory=Server.MapPath("") +"\\SearchEng\\";

proc.StartInfo.FileName=Fichier;

try

{

proc.Start();
proc.WaitForExit();

proc.Close();

}
catch(Exception ex)

{

this.lblerror.Text=ex.Message;

}

}

************************************************** ******************

string Fichier=Server.MapPath("")+\\SearchEng\\request.ba t;
Response.Write(Fichier)

It does return the physical path of the file starting from
C:\myApplication\SearchEng\request.bat.

But if don't run the file from the physical path (example : if fichier
= SearchEng\request.bat) it does give me an error : The system cannot
find the file specified.

I did another test: When i manually click on the request.bat file it
does execute and returns me the right answers.

This is what i get on my dos screen when i run the bat file with my
code.

C:\myApplication\SearchEng>set
path="C:\myApplication\SearchEng";C:\WINDOWS\syste m32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program
Files\ATI Technologies\ATI Control Panel;C:\Program Files\Microsoft SQL
Server\80\Tools\BINN;C:\bin C:\myApplication\SearchEng>java -jar
"C:\myApplication\SearchEng\SearchEngine.jar" GOOGLE/EPS/ gps IPSearch
Version 1.22 All rights reserved 2005 my company Researche in
progress ...... Error Results are saved in the Results.xml

You can see research is in progress. I think the Process end before the
SearchEngine.jar finishes executing.

But when i run it manually i don't no error, Very strange

I tried this proc.WaitForExit(900000) or proc.WaitForExit() but still
ended without success.

The content of my batch file is :
set path="C:\myApplication\SearchEng";%path%
java -jar "C:\myApplication\SearchEng\SearchEngine.jar" GOOGLE/EPS/ gps

This batch file execute : SearchEngine.jar in dos then it saves the
results in Results.xml

Then i get the results then list them in a treeview.

Have a wonderfull day.
Feb 3 '06 #3
string Fichier=Server.MapPath(@"SearchEng\request.bat");
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"em******@hotmail.com" wrote:
Hi every one,

I am trying to run a batch file using my asp.net application.

I am using the Process class to run the batch file. When I run my web
application, In the task manager, i could see cmd.exe with ASPNET as a
user. But nothing happens. It can't execute the batch file.

This is the code i am using to run the batch file:

private void Request()

{

string Fichier=Server.MapPath("")+"\\SearchEng\\request.b at";

Process proc=new System.Diagnostics.Process();

proc.StartInfo.WindowStyle=ProcessWindowStyle.Maxi mized;
proc.StartInfo.WorkingDirectory=Server.MapPath("") +"\\SearchEng\\";

proc.StartInfo.FileName=Fichier;

try

{

proc.Start();
proc.WaitForExit();

proc.Close();

}
catch(Exception ex)

{

this.lblerror.Text=ex.Message;

}

}

************************************************** ******************

string Fichier=Server.MapPath("")+\\SearchEng\\request.ba t;
Response.Write(Fichier)

It does return the physical path of the file starting from
C:\myApplication\SearchEng\request.bat.

But if don't run the file from the physical path (example : if fichier
= SearchEng\request.bat) it does give me an error : The system cannot
find the file specified.

I did another test: When i manually click on the request.bat file it
does execute and returns me the right answers.

This is what i get on my dos screen when i run the bat file with my
code.

C:\myApplication\SearchEng>set
path="C:\myApplication\SearchEng";C:\WINDOWS\syste m32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program
Files\ATI Technologies\ATI Control Panel;C:\Program Files\Microsoft SQL
Server\80\Tools\BINN;C:\bin C:\myApplication\SearchEng>java -jar
"C:\myApplication\SearchEng\SearchEngine.jar" GOOGLE/EPS/ gps IPSearch
Version 1.22 All rights reserved ¬ 2005 my company Researche in
progress ...... Error Results are saved in the Results.xml

You can see research is in progress. I think the Process end before the
SearchEngine.jar finishes executing.

But when i run it manually i don't no error, Very strange

I tried this proc.WaitForExit(900000) or proc.WaitForExit() but still
ended without success.

The content of my batch file is :
set path="C:\myApplication\SearchEng";%path%
java -jar "C:\myApplication\SearchEng\SearchEngine.jar" GOOGLE/EPS/ gps

This batch file execute : SearchEngine.jar in dos then it saves the
results in Results.xml

Then i get the results then list them in a treeview.

Have a wonderfull day.

Feb 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SkySea | last post by:
Hi! Any help on this would be appreciated... In an HTML document that lists instructions on installing some software, there's a point where a DOS batch file needs to be run in order to copy...
1
by: Rob | last post by:
I'm running a batch file using the Shell function. When I manually launch the batch file, the window remains open, since I use the 'pause' statement. But when I launch the batch file within...
4
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup)...
4
by: carrot | last post by:
With .Net Studio, I have a solution includes some projects. I want to execute a batch file during build solution time. For example, 1'st project is builded. 2'nd project is builded. " a batch...
6
by: Charles Neitzel | last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running...
1
by: Charles | last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running...
1
by: steve | last post by:
Hi all, Here's some work in progress that should allow you to run a batch file as a custom action in a VS deployment project. Yup I know you can use js or wsh, but the target may not have...
4
ck9663
by: ck9663 | last post by:
hi guys this is a little challenging, at least for me...here goes... i have to run a DOS batch file from a server. with some parameters that i need to pass. these parameters can be found on a...
14
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.