Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

CommandLine help please

vb.net pass command to console

  • Please log in to reply
18 replies to this topic

#1 jurru

jurru

    CC Newcomer

  • Member
  • PipPip
  • 23 posts
  • Programming Language:C, C++, C#, Visual Basic .NET
  • Learning:C, C++, C#, Visual Basic .NET

Posted 29 September 2012 - 04:44 AM

Can anyone help me to pass a command to console for the following file output operation:

c:\>myApp.exe -o outputfile.txt inputfile.txt

I would like to use button click event
  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 29 September 2012 - 04:55 AM

do you want your program to accept those parameters and perform, or what? where does the button click event come in?
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 jurru

jurru

    CC Newcomer

  • Member
  • PipPip
  • 23 posts
  • Programming Language:C, C++, C#, Visual Basic .NET
  • Learning:C, C++, C#, Visual Basic .NET

Posted 29 September 2012 - 05:08 AM

Orjan, thanks. In fact, I have a windows form with a command button. Under the command button event, I try to call my a dos application that helps me convert file1 to file2.

I give the file names of the input and output files as String

It is like:

Command_click (..)
Dim fileOut as String
Dim fileIn as String

Console myApp.exe -o fileOut fileIn

'fileIn is converted to fileOut using my doss application myApp.exe



If I do it "manually", I have to open console, then change to the application directory and use the command I showed above. Instead, I would like to do it with a command button without my manual intervention to the windows console. I am suing VS 2008
  • 0

#4 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 29 September 2012 - 06:00 AM

You can do that using Process.Start method. See the example at the bottom of that link.
  • 0

#5 jurru

jurru

    CC Newcomer

  • Member
  • PipPip
  • 23 posts
  • Programming Language:C, C++, C#, Visual Basic .NET
  • Learning:C, C++, C#, Visual Basic .NET

Posted 29 September 2012 - 07:15 AM

CC Devotee, thanks for the link. I tired to adapt the code as follows

Process.Start("C:\Windows\system32\cmd.exe", "C:\myDosApp.exe -o Output.txt Input.txt")

Windows console pops up but didn't take the argument "C:\myDosApp.exe -o Output.txt Input.txt". Instead, it opens up with the directory path of VS debug.

I would like to make clear that 'myDosApp.exe' is an external DOS application that reads Input.txt and creates Output.txt.
  • 0

#6 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 29 September 2012 - 07:20 AM

Well, I understand that the program to which you are trying to lunch with arguments is an external program.

However, you don't need to start cmd.exe to lunch with arguments but you can start your external program explicitly, e.g. --
Process.Start("C:\\myDosApp.exe", " -o Output.txt Input.txt")
.
  • 0

#7 jurru

jurru

    CC Newcomer

  • Member
  • PipPip
  • 23 posts
  • Programming Language:C, C++, C#, Visual Basic .NET
  • Learning:C, C++, C#, Visual Basic .NET

Posted 29 September 2012 - 07:54 AM

With that, myDosApp.exe tried to open with Windows security alert. I authorized to run. But nothing has happend, no output file is created.
  • 0

#8 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 29 September 2012 - 08:05 AM

With that, myDosApp.exe tried to open with Windows security alert. I authorized to run. But nothing has happend, no output file is created.

You mean you don't want to provide arguments to your program (myDosApp.exe)? Rather, program will read input from the input.txt file and write outputs to output.txt? I mean input.txt file will be the input-stream for your dos program and output.txt will be the output-string?
  • 0

#9 jurru

jurru

    CC Newcomer

  • Member
  • PipPip
  • 23 posts
  • Programming Language:C, C++, C#, Visual Basic .NET
  • Learning:C, C++, C#, Visual Basic .NET

Posted 29 September 2012 - 08:14 AM

You mean you don't want to provide arguments to your program (myDosApp.exe)? Rather, program will read input from the input.txt file and write outputs to output.txt? I mean input.txt file will be the input-stream for your dos program and output.txt will be the output-string?


Kernelcoder, thank you so much.

I would like to give argument to myDosApp.exe indeed. What you have showed me has worked but if I do some manipulation.

In fact, the process argument was pointing to the VB debug path to find myDosApp.exe and the associated input file.

However, when I put the two files (MyDosApp.exe and Input.txt) to the Debug path of my VB test program (where I am testing this process stuff), I see the output.txt is created.

I couldn't make VB test search from c:\MyDosApp.exe and c:\Input.txt to create c:\Output.txt . My VB project is in a differnt path

Edited by jurru, 29 September 2012 - 08:20 AM.

  • 0

#10 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 29 September 2012 - 08:20 AM

However, when I put the two files (MyDosApp.exe and Input.txt) to the Debug path of my VB test program (where I am testing this process stuff), I see the output.txt is created.

The code
Process.Start("C:\\myDosApp.exe", " -o Output.txt Input.txt")
reads the input file from c:\\input.txt and writes output to c:\\Output.txt.

However, in your case, what about trying like
Process.Start("C:\\myDosApp.exe", " -o C:\\Output.txt C:\\Input.txt")
?
  • 0

#11 jurru

jurru

    CC Newcomer

  • Member
  • PipPip
  • 23 posts
  • Programming Language:C, C++, C#, Visual Basic .NET
  • Learning:C, C++, C#, Visual Basic .NET

Posted 29 September 2012 - 08:52 AM

Kernelcoder, yes the second one has worked. One minor finishing. Is it possible to override security warnings to execute the external application? I mean, to make the process operation silent without user's interaction?
  • 0

#12 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 29 September 2012 - 09:02 AM

Kernelcoder, yes the second one has worked. One minor finishing. Is it possible to override security warnings to execute the external application? I mean, to make the process operation silent without user's interaction?

I'm not sure about that but just a shot -- can you try running visual studio (if you run the program from within VS) or the winform program itself in administrator mode?
  • 0





Also tagged with one or more of these keywords: vb.net, pass command to console

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download