By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,264 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

running command line progs in a controlled manner

P: n/a
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.SpecialFolde r.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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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)

"kevin bailey" <kb*****@freewayprojects.com> wrote in message
news:co*******************@news.demon.co.uk...
| 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.SpecialFolde r.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
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.