Home All Groups Group Topic Archive Search About

Access Console Application from Managed Code

Author
20 Jun 2006 3:33 PM
Will Asrari
I am working on a project now for a client that requires all managed code.
I have rewritten about 60% of the code and functionality in C# and have now
come to the complicated part of picking apart the existing stored procedure
and "managing" it.  Two tasks that I am outing from the stored procedure are
as follows:

1) execution of a .vbs that creates a .txt file (CSV) of user information
2) loading of said text file into an .exe and executing via command line

I can achieve the same result as 1 with a streamwriter.  This shouldn't be
too complicated.  Number 2 is what I am worried about.  The .exe will reside
on the same server where my application exists.  What would be the best way
to accomplish this task in a managed way?

I tried opening the exe on the server by double-clicking it and got the
following error:

"%E: Cannot find "\Ent=' parameter on the command line."

So there is no GUI. It seems as if this is a simple console application.

Here is the line from the old stored procedure:

SET @LaunchImportString = '\\' + @AppServer +
'\applicationName\sys_exe\ga_imp2.exe /GO /Ent=' + cast(@EntID as
varchar(20)) + ' /Store=1'
exec master..xp_cmdshell @LaunchImportString, no_output

Since I wasn't the original author of this software I don't know all of the
code.  I do know that I'm not going to use SQL server to access the command
line.

Thanks in advance,

- Will

Author
20 Jun 2006 3:46 PM
Nicholas Paldino [.NET/C# MVP]
Will,

    Basically, you will want to call the static Start method on the Process
class.  Create a variable which would be the same as @LaunchImportString and
then pass that to the method.

    Hope this helps.


--
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard.caspershouse.com


Show quote
"Will Asrari" <news[at]willasrari.comNOSPAM> wrote in message
news:%23b7N17HlGHA.3304@TK2MSFTNGP03.phx.gbl...
>I am working on a project now for a client that requires all managed code.
>I have rewritten about 60% of the code and functionality in C# and have now
>come to the complicated part of picking apart the existing stored procedure
>and "managing" it.  Two tasks that I am outing from the stored procedure
>are as follows:
>
> 1) execution of a .vbs that creates a .txt file (CSV) of user information
> 2) loading of said text file into an .exe and executing via command line
>
> I can achieve the same result as 1 with a streamwriter.  This shouldn't be
> too complicated.  Number 2 is what I am worried about.  The .exe will
> reside on the same server where my application exists.  What would be the
> best way to accomplish this task in a managed way?
>
> I tried opening the exe on the server by double-clicking it and got the
> following error:
>
> "%E: Cannot find "\Ent=' parameter on the command line."
>
> So there is no GUI. It seems as if this is a simple console application.
>
> Here is the line from the old stored procedure:
>
> SET @LaunchImportString = '\\' + @AppServer +
> '\applicationName\sys_exe\ga_imp2.exe /GO /Ent=' + cast(@EntID as
> varchar(20)) + ' /Store=1'
> exec master..xp_cmdshell @LaunchImportString, no_output
>
> Since I wasn't the original author of this software I don't know all of
> the code.  I do know that I'm not going to use SQL server to access the
> command line.
>
> Thanks in advance,
>
> - Will
>
Author
20 Jun 2006 4:02 PM
Michael Cummings
The following snippet (untested) should be relatively close to what your
looking to do:


System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.Arguments = @"/GO /Ent=" + EntID + @"/Store=1";
proc.StartInfo.WorkingDirectory = @"\\" + AppServer +
@"\applicationName\sys_exe";
proc.StartInfo.FileName = "ga_imp2.exe";
proc.Start();


Michael Cummings
michaelc AT magenic DOT com
Magenic Technologies

Show quote
"Will Asrari" <news[at]willasrari.comNOSPAM> wrote in message
news:%23b7N17HlGHA.3304@TK2MSFTNGP03.phx.gbl...
>I am working on a project now for a client that requires all managed code.
>I have rewritten about 60% of the code and functionality in C# and have now
>come to the complicated part of picking apart the existing stored procedure
>and "managing" it.  Two tasks that I am outing from the stored procedure
>are as follows:
>
> 1) execution of a .vbs that creates a .txt file (CSV) of user information
> 2) loading of said text file into an .exe and executing via command line
>
> I can achieve the same result as 1 with a streamwriter.  This shouldn't be
> too complicated.  Number 2 is what I am worried about.  The .exe will
> reside on the same server where my application exists.  What would be the
> best way to accomplish this task in a managed way?
>
> I tried opening the exe on the server by double-clicking it and got the
> following error:
>
> "%E: Cannot find "\Ent=' parameter on the command line."
>
> So there is no GUI. It seems as if this is a simple console application.
>
> Here is the line from the old stored procedure:
>
> SET @LaunchImportString = '\\' + @AppServer +
> '\applicationName\sys_exe\ga_imp2.exe /GO /Ent=' + cast(@EntID as
> varchar(20)) + ' /Store=1'
> exec master..xp_cmdshell @LaunchImportString, no_output
>
> Since I wasn't the original author of this software I don't know all of
> the code.  I do know that I'm not going to use SQL server to access the
> command line.
>
> Thanks in advance,
>
> - Will
>
Author
20 Jun 2006 5:14 PM
Will Asrari
Thanks to both of you for your input.  I will test this hopefully later this
week.

- Will

AddThis Social Bookmark Button