2011-05-24 74 views
0

可以說,我在shell格式多替換命令

"chdir * && whoami.exe >> $$$" 

我有這個replacecommand有這個

Dim ReplaceCommand as String = sCommand.Replace("*", UserDirect) 

我也希望$$$與選擇的用戶進行更換文件路徑。 我可以選擇文件路徑,但它永遠不會將它放入shell。

我已經試過

Dim ReplaceCommand1, ReplaceCommand2 as String = sCommand.Replace("*" & "$$$", UserDirect & filepath) 
Shell("cmd.exe" & ReplaceCommand1 & ReplaceCommand2) 

Dim ReplaceCommand as String = sCommand.Replace("*", UserDirect) & ("$$$", filepath) 
Shell("cmd.exe" & ReplaceCommand) 

Dim ReplaceCommand1 as String = sCommand.Replace("*", UserDirect) 
Dim ReplaceCommand2 as String = sCommand.Replace("$$$", filepath) 
Shell("cmd.exe" & ReplaceCommand1 & ReplaceCommand2) 

編輯: 得到一個路徑短的錯誤,當我在shell中使用逗號,而不是&

Dim ReplaceCommand1 as String = sCommand.Replace("*", UserDirect) 
Dim ReplaceCommand2 as String = sCommand.Replace("$$$", filepath) 
Shell("cmd.exe", ReplaceCommand1 , ReplaceCommand2) 

回答

0

你可以連替換的在一起:

Dim ReplaceCommand1 as String = sCommand.Replace("*", UserDirect).Replace("$$$", filepath) 
Shell("cmd.exe" & ReplaceCommand1) 
+0

啊謝謝你謝謝 – sealz 2011-05-24 13:28:50

0

部分的你示例不編譯語法錯誤的原因。

你沒有像你應該使用的Shell()。

Public Function Shell(
    PathName As String, 
    Optional Style As Microsoft.VisualBasic.AppWinStyle = MinimizedFocus, 
    Optional Wait As Boolean = False, 
    Optional Timeout As Integer = -1 
) As Integer 

從你給的例子看來,你只是把東西扔在一起。停下來思考了一分鐘:)

+0

炮彈運行完美,直到我去,要在一條線上:( – sealz 2011-05-24 13:15:40

+0

我指的是添加多個替換你編輯的部分,使用逗號代替&。 – Stijn 2011-05-24 13:18:42