Go Back   Techwatch Support Forums: Digital & Satellite TV, FTA, Cable, Computers, Mobile Phones, Apple and General Tech Forums > Tech Forums > Computers > PC Software



PC Software Computer software including operating systems, programs, applications, tools and drivers.

Reply
 
LinkBack Thread Tools
Old 21-01-12, 06:25 PM   #1 (permalink)
Senior Member
 
BL4K3Y's Avatar
 
Join Date: Apr 2008
Location: Colne, Lancashire
Posts: 7,004
Thanks: 247
Thanked 1,319 Times in 1,211 Posts
Default Advice Needed With Visual Basic

I am in the process of developing a console application using Visual Basic 2010.

I have all the code in place and the application functions as it should but I want to add a little extra to it. I have managed to get it to launch external applications (notepad, file explorer etc) but I want to set arguments for them.

For example, if a process is completed successfully, I want the user to see a message saying something like "Done" or "Failed" if the process wasn't successful. I understand that I need to put the said commands into variables but I am unsure how to do this.

Any help would be greatly appreciated, thank you.
BL4K3Y is offline   Reply With Quote
Old 21-01-12, 07:32 PM   #2 (permalink)
Senior Member
 
Join Date: Sep 2007
Posts: 213
Thanks: 17
Thanked 38 Times in 36 Posts
Default Re: Advice Needed With Visual Basic

I was going to have a go with this, but this page has more than enough information to get you going.
Code:
http://visualbasic.about.com/od/usingvbnet/a/prstrt.htm
I assume you're using Process.Start? When you dimension your new process, there's loads of properties, methods and events you can work with.

There should be summat that you can check to see if the process started and completed successfully. As it's a function with overloads you can pass arguments in. If the returned Process is not nothing then it was successful. It'll return nothing if it attaches to an already started process and also you can encapsulate it in a Try/Catch and capture the exceptions.

Good luck.

PS If you want to post a snippet, I may take a look.
edds is offline   Reply With Quote
The Following User Says Thank You to edds For This Useful Post:
BL4K3Y (21-01-12)
Old 21-01-12, 07:50 PM   #3 (permalink)
Senior Member
 
BL4K3Y's Avatar
 
Join Date: Apr 2008
Location: Colne, Lancashire
Posts: 7,004
Thanks: 247
Thanked 1,319 Times in 1,211 Posts
Default Re: Advice Needed With Visual Basic

Yes, Process.Start is what I am using .

From what I have read, I need to "parse" the command line output (the line(s) I want) in order to create a pass/fail answer.

Thanks for the link, I will have a read now.


Here is the code that initiates the desired process (the code works fine):
Quote:
Dim ecc As New ProcessStartInfo
ecc.WorkingDirectory = "D:\xell"
ecc.FileName = "D:\xell\python"
ecc.Arguments = "build.py nanddump.bin CDjasper xell-gggggg.bin"
ecc.UseShellExecute = False
ecc.RedirectStandardInput = True
Process.Start(ecc)
When the command is complete (when ran from the command line, not Visual Basic), it says "Done!". I want another message to display saying "Successful" and then give the user the option to proceed but if if fails, I want to have the application delete the file and go back to the start.

Last edited by BL4K3Y; 21-01-12 at 07:54 PM.
BL4K3Y is offline   Reply With Quote
Old 21-01-12, 07:59 PM   #4 (permalink)
Senior Member
 
Join Date: Sep 2007
Posts: 213
Thanks: 17
Thanked 38 Times in 36 Posts
Default Re: Advice Needed With Visual Basic

When I parse commandline args I just use Split, I have no knowledge of what yours do. I would assume the process you're starting can accept and handle these args?
edds is offline   Reply With Quote
Old 21-01-12, 08:01 PM   #5 (permalink)
Senior Member
 
BL4K3Y's Avatar
 
Join Date: Apr 2008
Location: Colne, Lancashire
Posts: 7,004
Thanks: 247
Thanked 1,319 Times in 1,211 Posts
Default Re: Advice Needed With Visual Basic

I guess this is what I am asking, I don't really know lol.

I want to parse the last line of the command (Done!") and use an IF ELSE statement to say true or false based on if it exists in the output.

If it helps, I managed to achieve this using batch script by using the FOR /F loop command.
BL4K3Y is offline   Reply With Quote
Old 21-01-12, 08:12 PM   #6 (permalink)
Senior Member
 
Join Date: Sep 2007
Posts: 213
Thanks: 17
Thanked 38 Times in 36 Posts
Default Re: Advice Needed With Visual Basic

I don't have any experience of console apps, so no idea if you could capture the word Done.
edds is offline   Reply With Quote
Old 05-02-12, 02:04 AM   #7 (permalink)
Senior Member
 
BL4K3Y's Avatar
 
Join Date: Apr 2008
Location: Colne, Lancashire
Posts: 7,004
Thanks: 247
Thanked 1,319 Times in 1,211 Posts
Default Re: Advice Needed With Visual Basic

Here is a code snippet:
Quote:
Dim compare As New Process
Dim output As String
compare.StartInfo.WorkingDirectory = "D:\nandpro"
compare.StartInfo.FileName = "C:\Windows\System32\fc"
compare.StartInfo.Arguments = "/b nand1.bin nand2.bin"
compare.StartInfo.UseShellExecute = False
compare.Start()
If output = "FC: no differences encountered" Then
Console.WriteLine("Success")
Console.ReadLine()
Else
Console.WriteLine("Failed")
Console.ReadLine()
FC (file compare) is an external application, the result "FC: no differences encountered" comes back if the NAND dumps match. I want my application to then say "Successful" if this is the case or "Failed" if it isn't.

I hope the code snippet can help you understand more of what I wish to achieve, thanks for any help .
BL4K3Y is offline   Reply With Quote
Old 16-02-12, 05:39 AM   #8 (permalink)
Senior Member
 
BL4K3Y's Avatar
 
Join Date: Apr 2008
Location: Colne, Lancashire
Posts: 7,004
Thanks: 247
Thanked 1,319 Times in 1,211 Posts
Default Re: Advice Needed With Visual Basic

Hello again.

I am at the stage where I can get a varied output (success/fail message) when the process is executed but now I want to see the actual process output in the console window in "real time" because I need to be able to see what is happening.

From what I have read on the internet, I believe I need to somehow utilise the "OutputDataReceived" event to do this. I have looked at many threads and even looked at some code samples on MSDN but I cannot understand it one bit.

Would somebody be kind enough to show me a sample of how this event works so that I have an idea on how to work with it in my application?

Thanks in advance for any help or advice .

Last edited by BL4K3Y; 16-02-12 at 05:41 AM.
BL4K3Y is offline   Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Advice needed for card share GJB31 Satellite Help 2 13-09-11 09:12 PM
advice needed afc4life Satellite Help 5 08-09-11 09:34 AM
Visual Basic Ideas BL4K3Y PC Software 8 13-02-11 03:51 PM
Beginners advice needed CC81 Satellite Help 2 18-09-10 10:04 PM
Wireless advice needed alboking_uk Broadband 0 30-07-10 08:42 PM


All times are GMT +1. The time now is 06:01 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.