473,513 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5395
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
862
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
5352
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
22027
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
4375
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
11193
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
4786
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
2952
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
4733
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
1699
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
13844
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
7264
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
7386
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7534
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5689
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,...
0
4749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3236
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
459
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.