473,408 Members | 1,907 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,408 software developers and data experts.

Running command line from aspx page

Hi there,

i'm trying to run a powershell script from a aspx page.

Here's the code:
//Powershell arguments
String powershell = "C:\\WINDOWS\\system32\
\windowspowershell\\v1.0\\powershell.exe";
String args = " -PSConsoleFile \"C:\\Program Files\
\Microsoft\\Exchange Server\\bin\\exshell.psc1\" -noexit -command \".
\'C:\\Program Files\\Microsoft\\Exchange Server\\bin\
\Exchange.ps1\'\"";

//Process class instance
System.Diagnostics.Process proc = new
System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;

//Process file and arguments
proc.StartInfo.FileName = powershell;
proc.StartInfo.Arguments = args;
// Démarrage du processus.
proc.Start();

//Data
StreamWriter sw = null;

string output = proc.StandardOutput.ReadToEnd();
sw = new StreamWriter("C:\\temp\\log.txt");
sw.WriteLine(output);
Console.WriteLine(output);

//Wait till exit
proc.WaitForExit();
proc.Close();
I can see very well the process running in the task manager, but i
can't have output log, so I don't know what's going on.
I'm running it on a windows server 2003.

Any help will be appreciated. Thanks in advance.
Nov 30 '07 #1
2 3138
Any help will be appreciated. Thanks in advance.

Hi,

Try putting your proc.WaitForExit(); line after proc.Start();

I think your getting the output of the process before the process
has had a chance to execute.

HTH,
Chris.

//Process class instance
System.Diagnostics.Process proc = new
System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;

//Process file and arguments
proc.StartInfo.FileName = powershell;
proc.StartInfo.Arguments = args;
// Démarrage du processus.
proc.Start();
//Wait till exit
proc.WaitForExit();

//Data
StreamWriter sw = null;

string output = proc.StandardOutput.ReadToEnd();
sw = new StreamWriter("C:\\temp\\log.txt");
sw.WriteLine(output);
Console.WriteLine(output);
proc.Close();
Nov 30 '07 #2
I tried it didn't work.
I also tried to put "test" just in the string output line, it doesn't
work either.
It didn't pu test in the log.txt file.
Nov 30 '07 #3

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

Similar topics

9
by: **ham | last post by:
"Visual Studio .NET has detected that the specified Web server is not running ASP.NET version 1.1. You will be unable to run ASP.NET Web applications or services." This is the message I get each...
5
by: Shahnaz Yousuf | last post by:
Following is the sample code of my .aspx file <%@ Page Language="C#" %><Script Runat="Server"> void Page_Load(Object sender, EventArgs EvArgs) { Response.Write("Hello World"); } </Script>...
4
by: louise raisbeck | last post by:
Hi I know I may be repeating some past questions but i wasnt sure if i added on to these if they would appear in the 'new list'! I have IIS 5 installed, IE 6 and visual studio .net 2003. When i...
13
by: David Lozzi | last post by:
Howdy My following script is not processing at all! <script runat="server"> Sub Page_Load(sender as Object, e as EventArgs) lblWelcome.text = "hello" End Sub </script>
16
by: TB | last post by:
Hi all: If you think that the following comments are absolute amateurish, then please bear with me, or simply skip this thread. A couple of months back I made the decision to initiate a...
1
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the...
1
by: daniel_xi | last post by:
Hi all, I am running a VS 2003 .NET project on my client machine (Win 2000 SP4, ..NET framework 1.1), running an ASP.NET application on a remote web server (Win 2000 Server, IIS 6.0, .NET...
3
by: Morten Snedker | last post by:
On the load part of 6 differint aspx pages I wish to run the same code. Instead of having the same code on 6 pages it would be kind of nice to have it in one place and include/call it. How...
6
by: tvaughan77 | last post by:
Hi, I have some code that I want to use to run a command line utility and I want to be able to run it from an aspx page running under IIS. The command line utility is a local utility running on...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.