Console use in a service

VBAHole22

Contributor
Joined
Oct 21, 2003
Messages
432
Location
VA
I have an old app that I run inside of a dos prompt (console, command window, whatever you want to call it) I would like to incorporate it into a web service so it runs on my server when I call it.

Trouble is the code that works in a windows app doesn't want to run in a windows service. Are there restrictions about a service spawning a console (using cmd.exe) on the server?

Any suggestions?

This is the code that doesn't work on the service but does on a windows app:


<WebMethod(Description:="Convert")> _
Public Function FConvert(ByVal NFile As String) As String

Dim myProcess As Process = New Process
Dim s As String
Dim MyBool() As Boolean
Dim myStr As String
Dim sErr As StreamReader
Dim sOut As StreamReader
Dim sIn As StreamWriter
Dim cmdString As String
cmdString = "fme dgn2sdeAnno1.fme --SourceDataset_IGDS " & NFile

Try
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.CreateNoWindow = False
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardError = True
myProcess.StartInfo.RedirectStandardOutput = True

myProcess.Start()
sErr = myProcess.StandardError
sOut = myProcess.StandardOutput
sIn = myProcess.StandardInput
sIn.AutoFlush = True
sIn.Write("cd C:\Samples\Testfme" & System.Environment.NewLine)
sIn.Write(cmdString & System.Environment.NewLine)

Do While Not myProcess.HasExited
If Not myProcess.HasExited Then
sIn.Write("exit" & System.Environment.NewLine)
End If
Loop

Catch ex As Exception
Console.WriteLine(ex.Message)

Finally

sIn.Close()
sOut.Close()
sErr.Close()
myProcess.Close()

End Try

Return "Done"
End Function
 
Back
Top