473,651 Members | 3,036 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any way to capture errors from Shell command

I want to programmaticall y capture an error that is done from a Shell
command in VB.Net code.

What I have is a Test.sql file that looks like

---------------------------------------------------
select * from Table1
GO
select * from Table2
GO
----------------------------------------------------

Then in my vb.net code I have:

Private Sub btnRun_Click(By Val sender As System.Object, _
ByVal e As System.EventArg s) Handles btnRun.Click

Shell("osql -U UserID1 -P Password1 -S MyServer" & _
"-d MyDatabase -i C:\Test.sql -o C:\Output.sql", _
AppWinStyle.Nor malFocus)

End Sub

Is there anyway inside the VB.Net code to capture an error if it
occurs. If I'm required to change my Test.sql file, that is fine. I
have access to this file created.

I'm wanting to run a series of these commands (some may be
updates/creates/etc) But if there is an error, I want to stop.

Thanks...

Nov 29 '05 #1
8 6253
st********@hotm ail.com wrote:
I want to programmaticall y capture an error that is done from a Shell
command in VB.Net code.

What I have is a Test.sql file that looks like

---------------------------------------------------
select * from Table1
GO
select * from Table2
GO
----------------------------------------------------

Then in my vb.net code I have:

Private Sub btnRun_Click(By Val sender As System.Object, _
ByVal e As System.EventArg s) Handles btnRun.Click

Shell("osql -U UserID1 -P Password1 -S MyServer" & _
"-d MyDatabase -i C:\Test.sql -o C:\Output.sql", _
AppWinStyle.Nor malFocus)

End Sub

Is there anyway inside the VB.Net code to capture an error if it
occurs. If I'm required to change my Test.sql file, that is fine. I
have access to this file created.

I'm wanting to run a series of these commands (some may be
updates/creates/etc) But if there is an error, I want to stop.

Thanks...


Why not connect through ADO? Then you will have access to the error, if
any.

Chris
Nov 29 '05 #2
We're currently using ADO. But because our scripts are so large, we
are having to parse these files because of the GO's.

Right now, to run these scripts thru VB and ADO, it takes 3 hours. In
query analyzer it takes 30 minutes.

We're trying to find an alternative to parsing the files. But we need
to handle errors so our customer doesn't continue if there's a problem.

Thanks

Nov 29 '05 #3
Standish,

If you want to use instead shell the application start than you can get the
commandline message.

Just a sample that I copied from my HKW database.
\\\
Dim p As New Process
Dim pi As New ProcessStartInf o
pi.UseShellExec ute = False
pi.RedirectStan dardOutput = True
pi.Arguments = "www.google.com "
pi.WorkingDirec tory = "C:\\windows\\s ystem32"
'this for nt* computers
pi.FileName = "ping"
p.StartInfo = pi
p.StartInfo = pi
p.Start()
Dim sr As IO.StreamReader = p.StandardOutpu t
Dim sb As New System.Text.Str ingBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW( input))
input = sr.Read
Loop
MessageBox.Show (sb.ToString)
///

I hope this helps,

Cor
Nov 29 '05 #4
Once you get the messages, how would you know there was an error?

Nov 29 '05 #5
i have once writte a program in VB.Net 2003 that would import a mysql
dump file from 7,5 GB
first i looped through the file from start to end to and converted the mysql
dialect to MS SQL dialect for the DDL
then i looped again to convert all inserts on the fly and executed them (
with 1000 inserts at a time )

this program ran for +- 20 minutes to import this file

computers used :

client computer AMD XP 2000 + with Windows 2000 with 512 MB ram

server DELL 4600 Poweredge Dual XEON 2,8 GHZ with 6 GB MEM 800 GB RAID 10
running SQL server enterprise and Windows 2000 advanced server
with PAE and AWE extensions enabled

The program was written in VB.Net 2003 and used the ADO.NET command object
to execute the sql batches a string builder was used to create the SQL from
the file data

so how big are your sql batch files ?? if you run in such performance
problems ,,,,, as you do not even have to convert the SQL dialect

maybe if you could show some of the SQL and how you process it we might be
able to help you in this task

regards

Michel Posseth [MCP]


<st********@hot mail.com> schreef in bericht
news:11******** *************@g 44g2000cwa.goog legroups.com...
Once you get the messages, how would you know there was an error?

Nov 29 '05 #6
You should try using SQLDMO. This is a programmatic interface you can use to
run the script, I think it should be the same as using query analyzer in
terms of what it does.

<st********@hot mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I want to programmaticall y capture an error that is done from a Shell
command in VB.Net code.

What I have is a Test.sql file that looks like

---------------------------------------------------
select * from Table1
GO
select * from Table2
GO
----------------------------------------------------

Then in my vb.net code I have:

Private Sub btnRun_Click(By Val sender As System.Object, _
ByVal e As System.EventArg s) Handles btnRun.Click

Shell("osql -U UserID1 -P Password1 -S MyServer" & _
"-d MyDatabase -i C:\Test.sql -o C:\Output.sql", _
AppWinStyle.Nor malFocus)

End Sub

Is there anyway inside the VB.Net code to capture an error if it
occurs. If I'm required to change my Test.sql file, that is fine. I
have access to this file created.

I'm wanting to run a series of these commands (some may be
updates/creates/etc) But if there is an error, I want to stop.

Thanks...

Nov 29 '05 #7
Cor,

"Cor Ligthert [MVP]" <no************ @planet.nl> schrieb:
Just a sample that I copied from my HKW database.
:-)
\\\
Dim p As New Process
Dim pi As New ProcessStartInf o
pi.UseShellExec ute = False
pi.RedirectStan dardOutput = True
pi.Arguments = "www.google.com "
pi.WorkingDirec tory = "C:\\windows\\s ystem32"
'this for nt* computers


I'm not sure what the comment in the snippet above is referring to. I'd
replace the double backslashes by single backslashes. This should work with
Windows NT too.

In addition to your reply, it's worth a look if the application writes error
messages to the error stream ('RedirectStand ardError'). This would make
analyzing the application's output easier.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 30 '05 #8
Herfried,

I changed it in my HKW.

I could have better used another one, this was first a C# sample made from
another VBnet one that is in HKW too.

Thanks

Cor
Nov 30 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8760
by: klappnase | last post by:
Hello, everyone, I am running python2.2.2 on a linux box. I want to call a shell command and get the PID of this child process so I have the possibility to abort the child process while it is still running. I tried the popen2 module for that: self.pp = popen2.Popen3(cmd)
1
3814
by: Pawel Banys | last post by:
Hello, There is an operation which can be performed at the shell prompt the following way: some_prg > result_file However, before "some_prg" can use files, they have to be converted and it can be done like this:
8
1333
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland newsgroups I learned that there is a function in stdlib.h called system. int system(const char *command); First question, is the system command ANSI compliant. Because I include <cstdlib> and write std::system(command.c_str()); it looks like an...
17
2093
by: MLH | last post by:
After running the following code snippet... MyURL = "http://tycho.usno.navy.mil/what.html" msXML.Open "GET", MyURL, False msXML.send I would like to execute code to perform essentially what would amount to clicking Edit, Select All, CTRL-C in Internet Explorer to capture some basic time 'n date text from the military site and parse it.
2
2842
by: Gerard Flanagan | last post by:
Hello, I have a third party shell script which updates multiple environment values, and I want to investigate (and ultimately capture to python) the environment state after the script has run. But running the script as a child process only sets values for that process, which are lost after execution. So I thought I could simply tack on an 'env' command line to the script input lines as shown below. However, using subprocess.Popen gives...
0
3483
by: j101 | last post by:
I am attempting to set up Q Capture on RH Linux (x86_64) using DB2 9 fp2, but there seems to be a general problem loading a specify MQ shared library "/opt/mqm/lib/libmqm_r.so". I have MQ v6 installed in the default directory and working. I can generate the similar errors in two ways (1) through the Replication Center attempting to validate the Q objects and (2) after manually creating the Q objects and running the asnqcap program. ...
3
6077
by: mike | last post by:
Hi Guys, Following piece of code can capture IOError when the file doesn't exist, also, other unknown exceptions can be captured when I press Ctrl-C while the program is sleeping(time.sleep). Now the question is: when I run the non-exist command, the exception cannot be captured. Here is the code: =================================== #!/usr/bin/python
2
3093
by: jdbartlett | last post by:
I'm trying to capture output from a command line utility (XMLSec), but only get an empty result. If I call the script from the command line, I see XMLSec's output, but I can't seem to capture it! My PHP installation is working correctly and captures other command line output just fine, XMLSec is the only exception I've found. I've also tried a couple of other systems to confirm this behavior. Capture methods I've tried include:
1
4471
Oryx
by: Oryx | last post by:
In another thread, someone posted... Well, I tried this, even using a different variable for the STDOUT lines: $output = exec($command . ' 2>&1', $outarr, $return); No joy. Even though $return was set to the error value, $outarr was empty as was $output.
0
8361
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8807
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8701
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8584
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7299
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.