473,395 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ASP.NET + Console + OutpUt

Hi,

I have a batch file which does file manipulation, I need
to call this batch file using asp.net and display the o/p
of the command e.g the copy command o/p of the batch file
on the browser.

Is this possible. If yes can any one guide me for the same.

Thanx
Prasad
Jul 21 '05 #1
3 5388
Hey Prasad, You can do it,
but you need to grant the right permissions to the ASP.NET identity,
OR
you need to run as some other identity. ASPNET by default does not have
permissions to start a process.

You can do the latter (run as a different identity) either using an
<impersonate .../> clause in web.config,
or by modifying machine.config to allow aspnet_wp.exe to use the system
identity. DANGER DANGER. Large flashing red lights and sirens!!! Do not
try this unless you know the risks!

Below is an example of the ASPX logic. I will not provide an example of how
to modify machine.config - you have to figure that out for yourself !

-Dino
================================================== ====
<html>
<head>
<title>Test: Start Process in ASPX</title>
<link rel="stylesheet" href="style/basic.css"/>
</head>

<script language="C#" runat=server>
private string RunProcess(string cmd) {
System.Diagnostics.Process p;
p= new System.Diagnostics.Process();
p.StartInfo.FileName= cmd;
p.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;

p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;
}
public void Page_Load(Object Sender, EventArgs E) {
string command= Request.Params["cmd"];

if ((command == null) || (command == "")) {
ContentFromTheCommand.Text= "No Command Specified.";
}
else {
String theOutput = RunProcess(command);
ContentFromTheCommand.Text= "<xmp>" + theOutput + "</" + "xmp>";
}
}
</script>

<body>

<h3>Start Process (Test)</h3>

<h6>This page is running as

<%= System.Security.Principal.WindowsIdentity.GetCurre nt().Name %>

</h6>
<form id="form1" runat="server">
command to run: <asp:textbox id="cmd" name="cmd"
value="c:\cygwin\bin\ls.exe" runat="server" columns="50" />
<br/>
<asp:button runat="server" Text="go!" />
</form>

<hr/>

<asp:label id="ContentFromTheCommand" runat="server"/>

</body>

</html>
"Prasad" <p_*******@hotmail.com> wrote in message
news:82****************************@phx.gbl...
Hi,

I have a batch file which does file manipulation, I need
to call this batch file using asp.net and display the o/p
of the command e.g the copy command o/p of the batch file
on the browser.

Is this possible. If yes can any one guide me for the same.

Thanx
Prasad

Jul 21 '05 #2
Hi Dino,
Thanx a million, it worked. One more query, if the
script takes a long time to process do i need to do any
special settings. Also i need soome good tutorials on
System.Diagnostics.Process.

Thanx
Prasad
-----Original Message-----
Hey Prasad, You can do it,
but you need to grant the right permissions to the ASP.NET identity,OR
you need to run as some other identity. ASPNET by default does not havepermissions to start a process.

You can do the latter (run as a different identity) either using an<impersonate .../> clause in web.config,
or by modifying machine.config to allow aspnet_wp.exe to use the systemidentity. DANGER DANGER. Large flashing red lights and sirens!!! Do nottry this unless you know the risks!

Below is an example of the ASPX logic. I will not provide an example of howto modify machine.config - you have to figure that out for yourself !
-Dino
================================================= =====
<html>
<head>
<title>Test: Start Process in ASPX</title>
<link rel="stylesheet" href="style/basic.css"/>
</head>

<script language="C#" runat=server>
private string RunProcess(string cmd) {
System.Diagnostics.Process p;
p= new System.Diagnostics.Process();
p.StartInfo.FileName= cmd;
p.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;

p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;
}
public void Page_Load(Object Sender, EventArgs E) {
string command= Request.Params["cmd"];

if ((command == null) || (command == "")) {
ContentFromTheCommand.Text= "No Command Specified.";
}
else {
String theOutput = RunProcess(command);
ContentFromTheCommand.Text= "<xmp>" + theOutput + "</" + "xmp>"; }
}
</script>

<body>

<h3>Start Process (Test)</h3>

<h6>This page is running as

<%= System.Security.Principal.WindowsIdentity.GetCurre nt ().Name %>
</h6>
<form id="form1" runat="server">
command to run: <asp:textbox id="cmd" name="cmd"
value="c:\cygwin\bin\ls.exe" runat="server" columns="50" /> <br/>
<asp:button runat="server" Text="go!" />
</form>

<hr/>

<asp:label id="ContentFromTheCommand" runat="server"/>
</body>

</html>
"Prasad" <p_*******@hotmail.com> wrote in message
news:82****************************@phx.gbl...
Hi,

I have a batch file which does file manipulation, I need
to call this batch file using asp.net and display the o/p of the command e.g the copy command o/p of the batch file on the browser.

Is this possible. If yes can any one guide me for the same.
Thanx
Prasad

.

Jul 21 '05 #3
also in machine.config there is a setting for the HTTP Request timeout, I
think it defaults to 90 seconds.
If you exceed or approach 90s, you will want to either change the timeout,
or (better) modify your app to process requests asynchronously. Ninety
seconds really is pushing the limits of the HTTP model.

I don't know of good sources of tutorials on System.Diagnostics.Process.
It's not a very deep or baroque object model. Best I can suggest is to
check the references. . . There are some examples. . .
http://msdn.microsoft.com/library/de...ClassTopic.asp

-Dino
Microsoft

"Prasad" <p_*******@hotmail.com> wrote in message
news:01****************************@phx.gbl...
Hi Dino,
Thanx a million, it worked. One more query, if the
script takes a long time to process do i need to do any
special settings. Also i need soome good tutorials on
System.Diagnostics.Process.

Thanx
Prasad
-----Original Message-----
Hey Prasad, You can do it,
but you need to grant the right permissions to the

ASP.NET identity,
OR
you need to run as some other identity. ASPNET by

default does not have
permissions to start a process.

You can do the latter (run as a different identity)

either using an
<impersonate .../> clause in web.config,
or by modifying machine.config to allow aspnet_wp.exe to

use the system
identity. DANGER DANGER. Large flashing red lights and

sirens!!! Do not
try this unless you know the risks!

Below is an example of the ASPX logic. I will not

provide an example of how
to modify machine.config - you have to figure that out

for yourself !

-Dino
================================================= =====
<html>
<head>
<title>Test: Start Process in ASPX</title>
<link rel="stylesheet" href="style/basic.css"/>
</head>

<script language="C#" runat=server>
private string RunProcess(string cmd) {
System.Diagnostics.Process p;
p= new System.Diagnostics.Process();
p.StartInfo.FileName= cmd;
p.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;

p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;
}
public void Page_Load(Object Sender, EventArgs E) {
string command= Request.Params["cmd"];

if ((command == null) || (command == "")) {
ContentFromTheCommand.Text= "No Command Specified.";
}
else {
String theOutput = RunProcess(command);
ContentFromTheCommand.Text= "<xmp>" + theOutput

+ "</" + "xmp>";
}
}
</script>

<body>

<h3>Start Process (Test)</h3>

<h6>This page is running as

<%= System.Security.Principal.WindowsIdentity.GetCurre nt

().Name %>

</h6>
<form id="form1" runat="server">
command to run: <asp:textbox id="cmd" name="cmd"
value="c:\cygwin\bin\ls.exe" runat="server"

columns="50" />
<br/>
<asp:button runat="server" Text="go!" />
</form>

<hr/>

<asp:label id="ContentFromTheCommand"

runat="server"/>

</body>

</html>
"Prasad" <p_*******@hotmail.com> wrote in message
news:82****************************@phx.gbl...
Hi,

I have a batch file which does file manipulation, I need
to call this batch file using asp.net and display the o/p of the command e.g the copy command o/p of the batch file on the browser.

Is this possible. If yes can any one guide me for the same.
Thanx
Prasad

.

Jul 21 '05 #4

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

Similar topics

6
by: Max | last post by:
Hi All, I am developing an application that needs to run in one of two modes: 1. If No command line param is provided the application should run as Window form. 2. If command line param is...
1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
2
by: Boba | last post by:
Hi, I'm programming a WinForm application. I would like to enter commands that will send output that will help me to locate bugs in the future. I know that there is a way to send output by...
7
by: ajikoe | last post by:
Hello All, It is said that : Enabling the console window is easy. From Microsoft Visual Studio®, right-click on the project and choose Properties. Change the output type from Windows Application...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
1
by: noleander | last post by:
Hi. I've got a C++ program written in Visual C++ 2003. The program is trivial, created with the Program-creation wizard: used the .NET "Form" template. The program has a trivial...
4
by: Bob | last post by:
I just recently noticed that when I start my applicatoin in debug mode, the IDE hangs (no disk or CPU activity) indefinitely (at least 20 minutes). Pausing the application shows that it's hung up...
2
by: Steve | last post by:
I have created a console app that simply prints out a message a couple times, then exits, here is the code: <code> for(int i = 0; i < 10; i++) { System.Threading.Thread.Sleep(500);...
3
by: Andrew Ducker | last post by:
We were using Console.Writeline from within our app, to do some routine debugging. And then we started having random problems when the code was run by a tester, on their own machine. We...
3
by: TC | last post by:
I'm trying to debug a console application, but I can't see the console output. I've seen many references which say that console output is supposed to appear on the Output window when the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.