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

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(outputStream); // An output stream will contains
the log

p = new Process();
p.StartInfo.FileName = "c:\\myapp.exe";
p.StartInfo.Arguments = string.Format(
"myarg=\"{0}\"",
arg
);
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
p.Start();
p.WaitForExit();
}
catch (Exception exc)
{
sw.WriteLine(exc.ToString());
throw exc;
}
}
void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
sw.Write(e.Data);
}

private void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
sw.Write(e.Data);
}

}

Is it the right way ?

Thanks,
Steve
Apr 7 '06 #1
3 1384
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*******@hotmail.com> a écrit dans le message de news:
11*********************@i39g2000cwa.googlegroups.c om...
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.WriteLine("Bonjour");
for (int i = 0; i < 100; i++)
{
Console.Write(i.ToString("00") + " ");
Thread.Sleep(25);
}
Console.WriteLine("\nFini");
}

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

Thanks,
Steve

"Steve B." <st**********@com.msn_swap_com_and_msn> a écrit dans le message
de news: %2****************@TK2MSFTNGP04.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*******@hotmail.com> a écrit dans le message de news:
11*********************@i39g2000cwa.googlegroups.c om...
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
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...
5
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...
2
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...
0
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...
2
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....
11
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...
0
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
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"...
2
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...
5
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.