将参数发送到CMD行或进程 [英] Sending Argument to CMD line or process

查看:96
本文介绍了将参数发送到CMD行或进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我需要的代码,除了我希望传递给我试图从我的vb.net应用程序运行的进程的参数。



该过程是一个命令行工具,需要一个特定的字符串,如下所示:



 1。 Filetool.exeC:\ myfile.exe





我需要在vb.net中写这样的东西试试并通过该过程的正确参数,以便它找到我希望执行的文件。



 Dim Arguments as string =Filetool .exe& & fi.fullname 





这个字符串的问题是它输出到cmd行或像这样的过程是不正确的用法:< br $>


 Filetool.exeC:\ Myfile.exe 





如何解决这个问题,以便完全按照我的第一个例子中显示的那样传递字符串(1.)

这将有所帮助如果我知道如何添加()目录,文件名和()结尾。还有如何在传递参数时添加空格



提前谢谢..











这是我到目前为止所得到的但仍未完全运作...



 Public Sub Dissassemble()
Dim process As New Process()
Dim Disasm As String =Disasm.exe''这个字符串是用于打开Disasm.exe
Dim Arguments As String = Disasm& & Label6.Text.ToString''这个字符串是给exe窗口命令使用Disasm.exe以及文件路径,文件名和扩展名等.Dasasm.exe C:\ folder \ folder \ somefile.exe
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.RedirectStandardError = True
process.StartInfo.CreateNoWindow = True
process。 StartInfo.FileName = Disasm''as string
process.StartInfo.Arguments = Arguments''As string
process.Start()
process.WaitForExit()''等到Disasm.exe退出
Dim output As String = process.StandardOutput.ReadToEnd()''将Dos内容返回给Textbox1.text
TextBox1.Text = output
Label13.Text = Arguments''不是很重要只是一个测试标签以查看参数字符串
End Sub

解决方案

下面是一个如何启动程序,传递命令行参数并在VB .NET中检索输出的工作示例



修订答案 - 发表于2013年3月2日美国东部时间上午9:25:

昏暗过程为新流程
尝试
''程序到由进程类启动:
Dim Disasm As String =C:\ Users \Mike \Downloads\DISASM\disasm.exe
''要传递给的字符串参数程序:
Dim Arguments As String =C:\Users\Mike \Downloads\DISASM\xxx.exe
''
process.StartInfo.WindowStyle = ProcessWindowStyle .Hidden
process.StartInfo.CreateNoWindow = True
Process.StartInfo.UseShellExecute = False
Process.StartInfo.RedirectStandardOutput = True
Process.StartInfo.RedirectStandardError = True
process.StartInfo.FileName = Disasm
''FullPathName o f将要处理的文件作为参数传递:
process.StartInfo.Arguments =参数
process.Start()
Dim output As String = process.StandardOutput.ReadToEnd()
process.WaitForExit()''等到程序结束
Debug.WriteLine(输出)
MsgBox(完成)
Catch ex As Exception
MsgBox(String .Concat(ex.Message,vbNewLine,vbNewLine,_
无法启动:& Disasm),_
MsgBoxStyle.Critical,_
Starting& Disasm)
结束尝试





使用Visual Basic .NET 2012测试


I have the desired code for my needs except for the argument that i wish to pass to the process that I am trying to run from my vb.net application.

the process is a command line tool that needs a specific string like so:

1. Filetool.exe "C:\myfile.exe"



I need to write something like this in vb.net to try and pass the correct argument to the process so that it will find the file I wish to perform the work on.

Dim Arguments as string = "Filetool.exe" & "" & fi.fullname



The problem to this string is it outputs to the cmd line or the process like this which is the incorrect usage:

Filetool.exeC:\Myfile.exe



How can I fix this so that the string will be passed exactly as it is shown in my first example (1.)
It would help If I knew how to add (") with a directory, filename and (") at the end. also how to add spaces when passing arguments

Thank you in advance..





This is what I have so far but still not working fully...

Public Sub Dissassemble()
            Dim process As New Process()
            Dim Disasm As String = "Disasm.exe" ''this string is for opening Disasm.exe 
            Dim Arguments As String = Disasm & " " & Label6.Text.ToString ''this string is to give the command to the exe window to use Disasm.exe and the filepath,filename and extension like so.. Disasm.exe C:\folder\folder\somefile.exe
            process.StartInfo.UseShellExecute = False
            process.StartInfo.RedirectStandardOutput = True
            process.StartInfo.RedirectStandardError = True
            process.StartInfo.CreateNoWindow = True
            process.StartInfo.FileName = Disasm ''As string
            process.StartInfo.Arguments = Arguments ''As string
            process.Start()
            process.WaitForExit() '' Wait until Disasm.exe exits
            Dim output As String = process.StandardOutput.ReadToEnd() ''Returns Dos contents to Textbox1.text
            TextBox1.Text = output
            Label13.Text = Arguments ''Not really important just a test label to see the arguments string
        End Sub

解决方案

Below is a working example of how to start a program, pass command line arguments and retrieve the output in VB .NET

Revised Answer - Posted 2 March 2013 9:25am EST:

Dim process As New Process
Try
    '' The program to be started by the Process Class:
    Dim Disasm As String = "C:\Users\Mike\Downloads\DISASM\disasm.exe"
    '' The string parameter to be passed to the program:
    Dim Arguments As String = "C:\Users\Mike\Downloads\DISASM\xxx.exe"
    ''
    process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    process.StartInfo.CreateNoWindow = True
    Process.StartInfo.UseShellExecute = False
    Process.StartInfo.RedirectStandardOutput = True
    Process.StartInfo.RedirectStandardError = True
    process.StartInfo.FileName = Disasm
    '' The FullPathName of the file to be processed is passed as the argument:
    process.StartInfo.Arguments = Arguments
    process.Start()
    Dim output As String = process.StandardOutput.ReadToEnd()
    process.WaitForExit() '' Wait until the program has ended
    Debug.WriteLine(output)
    MsgBox("Done")
Catch ex As Exception
    MsgBox(String.Concat(ex.Message, vbNewLine, vbNewLine, _
            "Unable to Start: " & Disasm), _
            MsgBoxStyle.Critical, _
            "Starting " & Disasm)
End Try



Tested with Visual Basic .NET 2012


这篇关于将参数发送到CMD行或进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆