Access Console Application from Managed Code

W

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
 
N

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.
 
M

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
 
W

Will Asrari

Thanks to both of you for your input. I will test this hopefully later this
week.

- Will
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top