从vb表单应用程序运行2个单独的cmd命令

时间:2013-02-06 12:52:36

标签: vb.net forms cmd

我希望我的程序打开cmd,更改目录然后执行命令:“copy / B file1 file2 output”

这就是我现在所拥有的。但所有发生的事情都是cmd窗口闪烁一秒但没有文件被创建

Dim cmd1 As String
Dim cmd2 As String
    cmd1 = "cd " & FolderFromFileName(imagename)
    cmd2 = "copy /B " & NameOnlyFromFullPath(imagename) & "+" & "TEMP.txt" & " " & TextBox1.Text
    Shell("cmd /c" & " " & cmd1 & " " & cmd2, AppWinStyle.NormalFocus)

请帮助,谢谢:)

1 个答案:

答案 0 :(得分:0)

您真的需要出现命令提示符吗?您可以使用system.io库在没有单独进程的情况下完成所有这些操作。如果您确实需要cmd提示,则可以创建流程。

Dim NewProcess = New Process
' a new process is created 
NewProcess.StartInfo.UseShellExecute = False
' redirect IO
' PVWCmd.StartInfo.RedirectStandardOutput = True
'       PVWCmd.StartInfo.RedirectStandardError = True
'      PVWCmd.StartInfo.RedirectStandardInput = True
' don't even bring up the console window
NewProcess.StartInfo.CreateNoWindow = False
' executable command line info
NewProcess.StartInfo.FileName = "cmd"

NewProcess.StartInfo.WorkingDirectory = "C:\"
'        NewProcess.StartInfo.Arguments = +" > """ + "LogFile.log" + """ 2>&1"

NewProcess.Start()