473,568 Members | 2,923 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 5404
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(stri ng cmd) {
System.Diagnost ics.Process p;
p= new System.Diagnost ics.Process();
p.StartInfo.Fil eName= cmd;
p.StartInfo.Win dowStyle =
System.Diagnost ics.ProcessWind owStyle.Hidden;
p.StartInfo.Red irectStandardOu tput = true;
p.StartInfo.Use ShellExecute = false;

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

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

<body>

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

<h6>This page is running as

<%= System.Security .Principal.Wind owsIdentity.Get Current().Name %>

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

<hr/>

<asp:label id="ContentFrom TheCommand" runat="server"/>

</body>

</html>
"Prasad" <p_*******@hotm ail.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.Diagnost ics.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(stri ng cmd) {
System.Diagnost ics.Process p;
p= new System.Diagnost ics.Process();
p.StartInfo.Fil eName= cmd;
p.StartInfo.Win dowStyle =
System.Diagnos tics.ProcessWin dowStyle.Hidden ;
p.StartInfo.Red irectStandardOu tput = true;
p.StartInfo.Use ShellExecute = false;

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

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

<body>

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

<h6>This page is running as

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

<hr/>

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

</html>
"Prasad" <p_*******@hotm ail.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.Diagnost ics.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_*******@hotm ail.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.Diagnost ics.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(stri ng cmd) {
System.Diagnost ics.Process p;
p= new System.Diagnost ics.Process();
p.StartInfo.Fil eName= cmd;
p.StartInfo.Win dowStyle =
System.Diagnos tics.ProcessWin dowStyle.Hidden ;
p.StartInfo.Red irectStandardOu tput = true;
p.StartInfo.Use ShellExecute = false;

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

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

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

<body>

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

<h6>This page is running as

<%= System.Security .Principal.Wind owsIdentity.Get Current

().Name %>

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

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

<hr/>

<asp:label id="ContentFrom TheCommand"

runat="server"/>

</body>

</html>
"Prasad" <p_*******@hotm ail.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 provided the application should run as a console application. For this i created a windows application with Main
1
5366
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 application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component...
2
22030
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 using the Console.Write command. The question is how can I see the outputs in the client machine ? Is there a specific programm to do it or Can I use...
7
4378
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 to Console Application. I use C# Standard Edition and I can't change the output type files from Windows Application to Console Application. I...
5
11207
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 to avoid the overhead of writing to the console if it is not visible, eg I am running inside a WinForm application. thanks
1
4799
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 single-pane form GUI. I've got some stdout print statements in the code ... but I cannot find where in the world the output text is appearing. For...
4
2961
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 at a line in a referenced assembly, one of my own, which is a simple Console.WriteLine() statement. The stack trace shows this line one level under...
2
4741
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); Console.WriteLine(String.Format("Sleeping...{0}", i)); } Console.WriteLine("Done!"); </code>
3
1709
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 couldn't replicate these problems on the developer machines. And then we eventually worked out that on the dev machines Console output was going to a...
3
13850
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 application is run in Debug mode. However, I just can't get that to work. I'm using Visual Studio 2005. I've confirmed that my application is compiled as a...
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.