[RESOLVED] Run console app from a windows form
Hey, I've made some console applications (two of them in my project) and then I decided to add a windows form into the project.
Now I have placed two separate command buttons onto the form, but I'm confused about the code which must be written for the command buttons to launch the console applications on click.
Normally, its something like:
Code:
Sub cmd_button1.Click()
frmnew.Show
frmthis.Hide
End Sub
What about loading the console application instead of another form? (The form and the console app's are all in the same project)
Re: Run console app from a windows form
Using Shell command you can execute the console application
Re: Run console app from a windows form
You can also use System.Diagnostics.Process.Start(path) and that will execute the app, or if it isn't an app, will open it in a suitable viewer.
Re: Run console app from a windows form
Quote:
You can also use System.Diagnostics.Process.Start(path) and that will execute the app
Well, that just simply switches back to the module in Visual Basic for the console application. I need it to load in the DOS window/command prompt (They are the same things right?)
Quote:
Using Shell command you can execute the console application
Could you please provide the code, I've tried the shell command, but it never worked correctly.
Re: Run console app from a windows form
As simple as that. The other parameters are optional.
Re: Run console app from a windows form
Well, I did do that, I went into the console application, right clicked, and chose 'copy full path' then I pasted the path into the path parameter of the Shell command.
Then when I ran the program in debug mode, it kept saying the object was not found. :(
Re: Run console app from a windows form
is any error????
u have to give the path in double quotes
Re: Run console app from a windows form
Quote:
Originally Posted by KrazyKomrade
Could you please provide the code, I've tried the shell command, but it never worked correctly.
why what error saying???
Re: Run console app from a windows form
there really isn't any kind of error, it simply says "File not found"
yes I did put the path in double quotes.
Is there any other way to go from the windows form to the console application using something other than the Shell command?
Re: Run console app from a windows form
Hi,
Are you giving the exe path or the application class file path?
You should give the executable file path.
Except path all are optional params.
Here is the syntax:
shell(path_Name[,style][,wait][,timeout])
path_name = executable file with the full path of the application
Style = a model of application window(ex minimize,normal etc).
Wait = a boolean value that prescriptive whether shell function has to wait vb.net finish before working. false is the default value.
TimeOut = a wait time that it needful by shell function to start working if Wait in true value.
Thanks.
Re: Run console app from a windows form
Here's something that may help in solving this problem:
All my files are location in one 'Solution' (.sln file) how can I switch between different objects (in this case from the windows form to the console application) using a command button?
Please note I'm using Visual Basic 2008 Express Edition.
Re: Run console app from a windows form
Check that the file is indeed at that path, and if it is, then please post the path, there might be a problem with the path itself, although it's very unlikely.
EDIT: I remember reading that Process.Start started VS. Are you sure that the file is an executable, and not some source file or something? Because using Shell implicitly says that the file you are trying to start is an executable of some kind. Please post the file name and extension so we can be sure.
Re: Run console app from a windows form
well, the console applications are named: 'server.vb' and 'client.vb'
each is in: C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\fs_lan_mes\fs_lan_mes\File Here
When I enter the code in the command button from the windows form (frm_main) I put this:
Shell("C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\fs_lan_mes\fs_lan_mes\file I want")
And I ignore all the other parameters.
Re: Run console app from a windows form
Quote:
Originally Posted by KrazyKomrade
well, the console applications are named: 'server.vb' and 'client.vb'
each is in: C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\fs_lan_mes\fs_lan_mes\File Here
When I enter the code in the command button from the windows form (frm_main) I put this:
Shell("C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\fs_lan_mes\fs_lan_mes\file I want")
And I ignore all the other parameters.
But the thing is, they ARE NOT EXECUTABLES! They are not applications! They are only the source code for an application! Hence the extension .vb, if they were applications, it would have been .exe or .com or .msi.
The Shell method asks for an executable at the specified path, and since it doesn't find an executable, it says 'Object not found'. The Process.Start method opens the source file with the default editor - just what it's supposed to do. If you want the button to start an application built from that source file, link it to the .exe file in the /bin directory.
Re: Run console app from a windows form
Quote:
But the thing is, they ARE NOT EXECUTABLES! They are not applications! They are only the source code for an application! Hence the extension .vb, if they were applications, it would have been .exe or .com or .msi.
Wow...I'm an idiot :p
Anyways, now I have to either find the executable files or make them myself.
Re: Run console app from a windows form
Quote:
Originally Posted by KrazyKomrade
Wow...I'm an idiot :p
Anyways, now I have to either find the executable files or make them myself.
Well, just press the Build button, and then look in the /bin folder and the executable will be there.:bigyello: