2013-02-06 28 views
0

我希望我的程序打開CMD,改變目錄,然後執行命令:「複製/ B文件1文件2輸出」運行從VB形式的2個獨立的CMD命令appliaction

這是我的時刻。但所發生的一切是一個第二一個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) 

請幫忙,謝謝:)

+0

刪除了「shell」標籤,與shell無關。閱讀「shell」的標籤wiki – Kent

+0

這是一個很好的例子,爲什麼你不應該使用Shell(),錯誤報告很糟糕。您需要「&&」在一條線上組合兩條命令。改爲使用FileStream類。 –

回答

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()