473,785 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process.Start from a web service and StandardOutput

Hi,

I'm written a Web Service that encapsulate the call to a command line
application.
The command line application is run using Process.Start, and I'd like to get
both standard ouput and standard error to create a log.

After some searches, I finally wrote this part of code :

public class MyClass {

private StreamWriter sw; // A Streamwriter where we can write the log
private Process p;

public void DoSomething(
string arg,
Stream outputStream
)
{
try
{
this.sw = new StreamWriter(ou tputStream); // An output stream will contains
the log

p = new Process();
p.StartInfo.Fil eName = "c:\\myapp.exe" ;
p.StartInfo.Arg uments = string.Format(
"myarg=\"{0}\"" ,
arg
);
p.StartInfo.Use ShellExecute = false;
p.StartInfo.Red irectStandardOu tput = true;
p.StartInfo.Red irectStandardEr ror = true;
p.OutputDataRec eived += new DataReceivedEve ntHandler(p_Out putDataReceived );
p.ErrorDataRece ived += new DataReceivedEve ntHandler(p_Err orDataReceived) ;
p.Start();
p.WaitForExit() ;
}
catch (Exception exc)
{
sw.WriteLine(ex c.ToString());
throw exc;
}
}
void p_ErrorDataRece ived(object sender, DataReceivedEve ntArgs e)
{
sw.Write(e.Data );
}

private void p_OutputDataRec eived(object sender, DataReceivedEve ntArgs e)
{
sw.Write(e.Data );
}

}

Is it the right way ?

Thanks,
Steve
Apr 7 '06 #1
3 1400
MyApp is going to run on the server, you know that, right? Spawning
apps like this is never a good idea. What does the app do?

Apr 7 '06 #2
The app actually runs on the server.
It is command line that can sign some assemblies using SIGNTOOL.EXE.

The Web Service is used to maintain a device application auto update feature
based on CAB files that must be signed with a certificate.

I send the raw dll and exe files to the webservice, and the WS first create
the cabfile using makecab (well working), and then sign the output cab with
SIGNTOOL.EXE (not well working).

Since it does not work, I want to get the process output to return to the
user in order to know why it did not worked.

I agree Process.Start and derivated in a WS is not a nice solution, but
building the full mecanims of creating and signing cab files is surely quite
complex. That's why we decided to use the existing tools, even if they are
command line tools.

We'll stay on this solution for now because of a release soon, but if you
have suggestion on other solution, we listen :)

Thanks,
Steve

"sirfunusa" <si*******@hotm ail.com> a écrit dans le message de news:
11************* ********@i39g20 00...legro ups.com...
MyApp is going to run on the server, you know that, right? Spawning
apps like this is never a good idea. What does the app do?

Apr 10 '06 #3
In orderto test, I've an incredibly complex command line app :

public static void Main()
{
Console.WriteLi ne("Bonjour");
for (int i = 0; i < 100; i++)
{
Console.Write(i .ToString("00") + " ");
Thread.Sleep(25 );
}
Console.WriteLi ne("\nFini");
}

Running this command line within a WS does not produce any output...

Thanks,
Steve

"Steve B." <st**********@c om.msn_swap_com _and_msn> a écrit dans le message
de news: %2************* ***@TK2MSFTNGP0 4.phx.gbl...
The app actually runs on the server.
It is command line that can sign some assemblies using SIGNTOOL.EXE.

The Web Service is used to maintain a device application auto update
feature based on CAB files that must be signed with a certificate.

I send the raw dll and exe files to the webservice, and the WS first
create the cabfile using makecab (well working), and then sign the output
cab with SIGNTOOL.EXE (not well working).

Since it does not work, I want to get the process output to return to the
user in order to know why it did not worked.

I agree Process.Start and derivated in a WS is not a nice solution, but
building the full mecanims of creating and signing cab files is surely
quite complex. That's why we decided to use the existing tools, even if
they are command line tools.

We'll stay on this solution for now because of a release soon, but if you
have suggestion on other solution, we listen :)

Thanks,
Steve

"sirfunusa" <si*******@hotm ail.com> a écrit dans le message de news:
11************* ********@i39g20 00...legro ups.com...
MyApp is going to run on the server, you know that, right? Spawning
apps like this is never a good idea. What does the app do?


Apr 10 '06 #4

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

Similar topics

3
10408
by: Al Cohen | last post by:
I'll start by warning that I'm a newbie to C# (but I've been programming for 25 years), so I may just be doing something reallyreally dumb. I'm writing a C# wrapper for a command-line application (pscp.exe, a secure file-copy app that's part of the excellent PuTTY SSH package). Getting pscp.exe to run properly was a piece of cake using the System.Diagnostics.Process class. The thing that I can't get to work is the ability to read...
5
3674
by: ask | last post by:
Hi NG I'm a bit new to programming c# and have a question regarding ftp by the command prompt. As far as I can see it should be possible to start a process and pipe command streams into it. But I cant make it work, it always stalls when I try to read the output: /// code 1 Process ftpProcess = new Process();
2
3206
by: Tobias Johansson | last post by:
Hello, I'm having what I believe a security problem to execute an executable file from a windows service in windows server 2003. It works fine in WIN XP SP2 The program(the service) itself just continues as if nothing where wrong after process.Start is executed and I get an Exit code from the process
0
1495
by: BasicQ | last post by:
I am running an executable from my aspx page with the click of a button. A date is passed as an argument. I am able to get the standardoutput from the Process(Exe) into the label of my page after the process has completed executing. My problem is I need to get the output in the label simultaneously when the EXE is running, not after it has completed executing. Just like when I run the Exe in the cmd prompt. In my code I am opening two...
2
2282
by: mwazir | last post by:
Hi all, I have a process thats starts in my application and only terminates when my application is terminated. I want to write the output and the errors of this process to a seperate log file. In order to do this, I spawned two threads. My code looks something like this ' Starting the process oProcessStartInfo = New ProcessStartInfo()
11
3756
by: Nurit N | last post by:
This is the third newsgroup that I'm posting my problem. I'm sorry for the multiple posts but the matter becoming urgent. I hope this is the right place for it... I have created a very simple batch file (echo hello world) and was trying to retrieve the standard output but every time I run the code it returns ExitCode as 1.
0
6746
by: Kirk | last post by:
The following C# web service works fine until you uncomment the lines setting UserName and Password. Then, Process.Start throws an Access is Denied Exception. This is with .NET 2.0, of course (1.1 does not support running a process as a different user). I'm running everything on Windows Server 2003. I have impersonation enabled in my web.config, and I'm using Integrated authentication on the IIS virtual directory that this aspx is in....
1
4856
by: Brad | last post by:
I have an issue trying to execute commands in a web service. The command starts under the specified user. However, it never completes its execution. I can execute simple commands like "echo HELLO" and cmd.exe starts but never terminates. I'm relatively new to .NET, so I may be forgetting some thing obvious. Thanks! Here's the code: using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols;
2
8634
by: Al | last post by:
I'm currently attempting to use PLink (the console component of PUTTY - see http://www.chiark.greenend.org.uk/~sgtatham/putty/) as a Telnet component as I may in future need to change to using SSH and this seems an ideal solution. I'm running it as a process and re-directing the standardinput/output/error However, despite working through all the different variations of code I can either think of or find I am unable to achieve true...
5
3458
by: =?Utf-8?B?Z215ZXJz?= | last post by:
Hello, I am attempting to start a cmd.exe process and pass several .vbs scripts (with additional parameters) and then read the output from the scripts and make "notes" in a DataTable (the "notes" not being the issue). Beginning with... Dim objProcess As Process Dim objProcessStartInfo As New ProcessStartInfo
0
9645
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
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
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
10091
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
9950
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
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
3
2879
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.