473,769 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#/IIS : Command line ouput can't be read when running under IIS

6 New Member
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 the same box as my IIS server, and the code works in Visual Studio, just not under IIS. Any suggestions?

The logs are totally silent on the issue. On line 36 (below), the log says:
"I read this from our process:" . . . .just blank after that.

Grrrr.....


Expand|Select|Wrap|Line Numbers
  1.     public class CommandLineUtils : ICommandLineUtils
  2.     {
  3.         private static readonly ILog log = LogManager.GetLogger(typeof(CommandLineUtils));
  4.  
  5.         private StringBuilder processStdOutput = null;
  6.  
  7.         /// 
  8.         /// <summary>
  9.         /// Executes an Interwoven command line utility
  10.         /// </summary>
  11.         /// <param name="clt">The utility to execute</param>
  12.         /// <param name="args">Any arguments to pass on the command line</param>
  13.         /// <returns>The string of output, as produced by running the command</returns>
  14.         /// 
  15.         public string ExecIwovCLT(string clt, string args)
  16.         {
  17.             log.Debug("Executing command: '" + clt + " " + args + "'");
  18.             processStdOutput = new StringBuilder("");
  19.  
  20.  
  21.             Process proc = new Process();
  22.             proc.StartInfo.FileName = clt;
  23.             proc.StartInfo.Arguments = args;
  24.             proc.StartInfo.UseShellExecute = false;
  25.             proc.StartInfo.RedirectStandardOutput = true;
  26.             proc.StartInfo.RedirectStandardError = true;
  27.  
  28.             proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
  29.             proc.ErrorDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
  30.  
  31.             try
  32.             {
  33.                 proc.Start();
  34.                 proc.BeginOutputReadLine();
  35.                 proc.WaitForExit();
  36.                 log.Debug("I read this from our process: \n" + processStdOutput.ToString());
  37.             }
  38.             catch (Win32Exception ex)
  39.             {
  40.                 log.Error("Could not execute the '" + clt + " " + args + "' command");
  41.                 log.Error(ex.ToString());
  42.             }
  43.             finally
  44.             {
  45.                 proc.Close();
  46.             }
  47.  
  48.             return processStdOutput.ToString();
  49.         }
  50.  
  51.  
  52.         /// 
  53.         /// <summary>
  54.         /// Event handler for process execution method (above)
  55.         /// </summary>
  56.         /// <param name="sendingProcess">process doing the outputting</param>
  57.         /// <param name="outLine">output line from the process</param>
  58.         /// 
  59.         private void proc_OutputDataReceived(object sendingProcess,
  60.                                              DataReceivedEventArgs outLine)
  61.         {
  62.             if (!String.IsNullOrEmpty(outLine.Data))
  63.             {                
  64.                 processStdOutput.Append(outLine.Data + Environment.NewLine);
  65.             }
  66.         }
  67.     }
  68. }
  69.  
Jan 3 '08 #1
6 2754
Plater
7,872 Recognized Expert Expert
I don't see anywhere where you actually read the data from the process (the in/out/error streams)
I see you have the eventhandlers, but they don't seem to ever look at the streams?
Jan 4 '08 #2
tvaughan77
6 New Member
I don't see anywhere where you actually read the data from the process (the in/out/error streams)
I see you have the eventhandlers, but they don't seem to ever look at the streams?
The line:
Expand|Select|Wrap|Line Numbers
  1. processStdOutput.Append(outLine.Data + Environment.NewLine);
is appending Stdout and Stderr lines to a StringBuffer class member variable.

I know that part works (i.e. that I can actually read stuff from a command line handle) because when I run this in my IDE and I try executing the DOS command "date" (for example), I can read the process' output and I echo the correct time.

When I move this code in to IIS, however, I just read nothing. . .an empty line.

BTW, I found out that the exit code of the Process is "1", but that's all the info I can get...it isn't throwing an exception or telling me why it's erroring out.
Jan 4 '08 #3
Plater
7,872 Recognized Expert Expert
Yeah, sorry, I went crosseyed and realized I was reading the eventhandlers wrong (oops).

Even if it exited with a zero, shouldn't it dump data into the error stream?

Maybe it never actually executed the file you are trying to run. Like if you tried to run a .vbs file but didn't have vbscript support on the computer. It wouldn't return any data to the in/out/error streams because it couldn't do anything, that would return a non-zero value for the return code.
Have you tried manually running the process on the IIS server machine?
Jan 4 '08 #4
tvaughan77
6 New Member
Yeah, sorry, I went crosseyed and realized I was reading the eventhandlers wrong (oops).

Even if it exited with a zero, shouldn't it dump data into the error stream?

Maybe it never actually executed the file you are trying to run. Like if you tried to run a .vbs file but didn't have vbscript support on the computer. It wouldn't return any data to the in/out/error streams because it couldn't do anything, that would return a non-zero value for the return code.
Have you tried manually running the process on the IIS server machine?
Yep, in my logs, I echo exactly what I'm trying to run:
Expand|Select|Wrap|Line Numbers
  1. Executing command: 'C:\Interwoven\TeamSite\bin\iwgetwfobj.exe 123'
  2. I read this from our process: 
  3.  
  4. 2008-01-04 11:08:18,583 DEBUG The process exit code is: '1'
  5.  
So if I copy and paste the command onto a DOS prompt on that server, I get the expected output (about 20 lines of XML).

Weird, huh?

To make things more weird, I even tried running some other command just before the iwgetwjobj command....and that works!

Just before I try running the iwgetwjobj.exe, I run "c:\\cygwin\\bi n\\ps.exe" and it returns a list of processes currently running on that server, and that works when I run it on the command line, from within my IDE, and (crucially) while running under IIS.

So I'm really kind of stuck as to why one exe will work and the other won't.
Both exe's have the same permissions (Everyone has Full Control).
Jan 4 '08 #5
Plater
7,872 Recognized Expert Expert
Did you run the ps.exe process in the same manor? capturing it's output(s) and setting shellexecute to false?
Jan 4 '08 #6
tvaughan77
6 New Member
Did you run the ps.exe process in the same manor? capturing it's output(s) and setting shellexecute to false?
Yep; exactly the same method used in both cases.
Expand|Select|Wrap|Line Numbers
  1.         public string GetReviewTaskOwner(int taskid)
  2.         {
  3.             //
  4.             // FIXME remove this ps.exe debugging call:
  5.             //
  6.             string testcommand = "C:\\cygwin\\bin\\ps.exe";
  7.             string testoutput = clUtils.ExecIwovCLT(testcommand, "");
  8.             log.Debug("The testoutput of running " + testcommand + " is \n'" + testoutput + "'\n");
  9.  
  10.             //
  11.             //  This is where the iwgetwfobj call is made
  12.             //
  13.             string fullPathClt = Path.Combine(iwbin, iwgetwfobj);            
  14.             string args = "" + taskid;
  15.             string commandLineOutput = clUtils.ExecIwovCLT(fullPathClt, args);
  16.  
  17.             string owner = getOwnerFromWfObjXML(commandLineOutput);
  18.  
  19.             return owner;
  20.         }
Jan 4 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
9587
by: Nicholas Then | last post by:
I am writing an application that will call a command line application. Basically I have set up the windows 2003 POP3/SMTP service and to change a password of a mailbox, I need to execute the following program: winpop changepwd somename@domain.com SomePassword I have the folowing code in a .NET app so that I can change the password using a GUI:
3
511
by: James D. Marshall | last post by:
Please point me to some articles that explain how to execute a dos type command and retrieve its output for processing. Thanks.
12
5377
by: Rhino | last post by:
I am having an odd problem: the sqlj command on my system doesn't work. I am running DB2 (LUW) V8 (FP8) on WinXP. I haven't done an sqlj program since Version 6 of DB2 (LUW) so I checked the manuals for the proper techniques to prepare an sqlj program. When I went to try the sqlj command, I got this: Exception in thread "main" java.lang.NoClassDefFoundError: sqlj/tools/Sqlj
2
5873
by: Adam Clauss | last post by:
I am building a GUI to wrap around some of the information/abilities contained within the program netsh. I have figured out how to use redirect the standardinput and standardoutput so that I can read/write from my application. The "easy" way to do this would be to spawn an instance of netsh everytime I need to execute a command, write the command to the input (including a quit command), and call ReadToEnd on the output. And this does...
5
7151
by: calmar | last post by:
Hi all, unfotunately, 'commands.getstatusoutput(command)' does not work under windows. Would there be any alternative? os.system also just provides the exit number I think. thanks a lot,
2
3384
by: Jim | last post by:
Hello, I need a program that will traverse a directory tree to ensure that there are unix-style line endings on every file in that tree that is a text file. To tell text files from others I want to use the unix "file" command (Python's "mimetypes" is not so good for me). But I am stuck on something about getting that output, and I'd greatly appreciate any pointers.
5
1679
by: qazwart | last post by:
I am reading from a "cvs rlog" command, and I need both the STDOUT and STDERR. Unfortunately, something very strange is happening. If I do this: $cmd = "$cvs_cmd -q rlog -NS -r$from_label::$to_label neo 2>&1"; // Hard coded module DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {"); if (!($cvs_fh = popen("$cmd", 'r'))) { generate_error("Canot open command \"$cmd\" for reading"); }
17
3379
by: Matt | last post by:
Hello. I'm having a very strange problem that I would like ot check with you guys. Basically whenever I insert the following line into my programme to output the arguments being passed to the programme: printf("\nCommand line arguement %d: %s.", i , argv ); The porgramme outputs 3 of the command line arguements, then gives a segmentation fault on the next line, followed by other strange
51
4158
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under Command Prompt or Browser or some other application? Ojas.
0
9589
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10049
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3965
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
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.