running command line progs in a controlled manner

K

kevin bailey

hi,

i am swamped by all the documentation and i can't find something relatively
simple.

a company has an intranet and they want a browser based application to
control data import/export. i need an apsx page to run dts packages on a
separate server.

after asking here and further investigation i am going to try this using
dtsrun.exe

which brings me to my question...

i can create a system.diagnostics.process object and run the program - but
how would i capture errors from this running.

the code i found is for VB and not ASP.NET and is at he end of this message.
when i tried to run it get Catch e As Win32Exception code produces Catch e
As Win32Exception.

where is a good place for ASP.NET examples?

thanks - kev




[Visual Basic]
Imports System
Imports System.Diagnostics
Imports System.ComponentModel


Namespace MyProcessSample
_
'/ <summary>
'/ Shell for the sample.
'/ </summary>
Public Class MyProcess
' These are the Win32 error code for file not found or access denied.
Private ERROR_FILE_NOT_FOUND As Integer = 2
Private ERROR_ACCESS_DENIED As Integer = 5


'/ <summary>
'/ Prints a file with a .doc extension.
'/ </summary>
Public Sub PrintDoc()
Dim myProcess As New Process()

Try
' Get the path that stores user documents.
Dim myDocumentsPath As String =
Environment.GetFolderPath(Environment.SpecialFolder.Personal)

myProcess.StartInfo.FileName = myDocumentsPath + "\MyFile.doc"
myProcess.StartInfo.Verb = "Print"
myProcess.StartInfo.CreateNoWindow = True
myProcess.Start()
Catch e As Win32Exception
If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then
Console.WriteLine((e.Message + ". Check the path."))

Else
If e.NativeErrorCode = ERROR_ACCESS_DENIED Then
' Note that if your word processor might generate
exceptions
' such as this, which are handled first.
Console.WriteLine((e.Message + ". You do not have
permission to print this file."))
End If
End If
End Try
End Sub 'PrintDoc


Public Shared Sub Main()
Dim myProcess As New MyProcess()
myProcess.PrintDoc()
End Sub 'Main
End Class 'MyProcess
End Namespace 'MyProcessSample
 
B

bruce barker

it depends on the program you run how you detect error. when you run a
program, you have access to its stdout, and stderr streams, and its
exitcode. some programs will return a special exitcode if they failed, some
don't. some will write errors to stderr, some stdout. dtsrun.exe is better
behaved than most.

-- bruce (sqlwork.com)



| hi,
|
| i am swamped by all the documentation and i can't find something
relatively
| simple.
|
| a company has an intranet and they want a browser based application to
| control data import/export. i need an apsx page to run dts packages on a
| separate server.
|
| after asking here and further investigation i am going to try this using
| dtsrun.exe
|
| which brings me to my question...
|
| i can create a system.diagnostics.process object and run the program - but
| how would i capture errors from this running.
|
| the code i found is for VB and not ASP.NET and is at he end of this
message.
| when i tried to run it get Catch e As Win32Exception code produces Catch e
| As Win32Exception.
|
| where is a good place for ASP.NET examples?
|
| thanks - kev
|
|
|
|
| [Visual Basic]
| Imports System
| Imports System.Diagnostics
| Imports System.ComponentModel
|
|
| Namespace MyProcessSample
| _
| '/ <summary>
| '/ Shell for the sample.
| '/ </summary>
| Public Class MyProcess
| ' These are the Win32 error code for file not found or access
denied.
| Private ERROR_FILE_NOT_FOUND As Integer = 2
| Private ERROR_ACCESS_DENIED As Integer = 5
|
|
| '/ <summary>
| '/ Prints a file with a .doc extension.
| '/ </summary>
| Public Sub PrintDoc()
| Dim myProcess As New Process()
|
| Try
| ' Get the path that stores user documents.
| Dim myDocumentsPath As String =
| Environment.GetFolderPath(Environment.SpecialFolder.Personal)
|
| myProcess.StartInfo.FileName = myDocumentsPath + "\MyFile.doc"
| myProcess.StartInfo.Verb = "Print"
| myProcess.StartInfo.CreateNoWindow = True
| myProcess.Start()
| Catch e As Win32Exception
| If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then
| Console.WriteLine((e.Message + ". Check the path."))
|
| Else
| If e.NativeErrorCode = ERROR_ACCESS_DENIED Then
| ' Note that if your word processor might generate
| exceptions
| ' such as this, which are handled first.
| Console.WriteLine((e.Message + ". You do not have
| permission to print this file."))
| End If
| End If
| End Try
| End Sub 'PrintDoc
|
|
| Public Shared Sub Main()
| Dim myProcess As New MyProcess()
| myProcess.PrintDoc()
| End Sub 'Main
| End Class 'MyProcess
| End Namespace 'MyProcessSample
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top