2012-08-03 2 views
1

어제도 어떤 이유로 작동했지만 오늘은 작동하지 않습니다. 나는 그것의 코드가 아니라 외부적인 문제라고 생각한다.이것을 줄일 수 있습니까? vb.net에서 프로세스를 만들었습니다. 4 번만 호출해야합니다.

어쨌든

Dim virtualFolder As String = "~/Scripts/" 
    Dim physicalFolder As String = Server.MapPath(virtualFolder) 
    Dim unixLogin As String = (USERNAME & "@" & COMPUTERNAME & ":" & UNIXSCRIPTNAME) 

    ' Send file to Unix server via pscp 
    Dim Proc As New System.Diagnostics.Process 
    Proc.StartInfo = New ProcessStartInfo("C:\Windows\System32\cmd.exe") 
    'MsgBox("/C C:\pscp.exe -pw " & PASSWORD & " " & physicalFolder & "\" & UNIXSCRIPTNAME & " " & unixLogin) 
    Proc.StartInfo.Arguments = "C:\pscp.exe -pw " & PASSWORD & " " & physicalFolder & "\" & UNIXSCRIPTNAME & " " & USERNAME & "@" & COMPUTERNAME & ":" & UNIXSCRIPTNAME 
    Proc.StartInfo.RedirectStandardInput = True 
    Proc.StartInfo.RedirectStandardOutput = False 
    Proc.StartInfo.UseShellExecute = False 
    'Proc.StartInfo.CreateNoWindow = True 
    Proc.Start() 
    ' Allows script to execute sequentially instead of simultaneously 
    Proc.WaitForExit() 

    ' Make file executable 
    Proc.StartInfo = New ProcessStartInfo("C:\plink.exe") 
    'MsgBox("-ssh -pw " & PASSWORD & " " & USERNAME & "@" & COMPUTERNAME & " chmod u+x ./" & UNIXSCRIPTNAME) 
    Proc.StartInfo.Arguments = "-ssh -pw " & PASSWORD & " " & USERNAME & "@" & COMPUTERNAME & " chmod u+x ./" & UNIXSCRIPTNAME 
    Proc.StartInfo.RedirectStandardInput = True 
    Proc.StartInfo.RedirectStandardOutput = False 
    Proc.StartInfo.UseShellExecute = False 
    ' Proc.StartInfo.CreateNoWindow = True 
    Proc.Start() 
    Proc.WaitForExit() 

    ' Execute File 
    Proc.StartInfo = New ProcessStartInfo("C:\plink.exe") 
    Proc.StartInfo.Arguments = "-ssh -pw " & PASSWORD & " " & USERNAME & "@" & COMPUTERNAME & " ./" & UNIXSCRIPTNAME 
    Proc.StartInfo.RedirectStandardInput = True 
    Proc.StartInfo.RedirectStandardOutput = False 
    Proc.StartInfo.UseShellExecute = False 
    'Proc.StartInfo.CreateNoWindow = True 
    Proc.Start() 
    Proc.WaitForExit() 

    ' Remove File 
    Proc.StartInfo = New ProcessStartInfo("C:\plink.exe") 
    Proc.StartInfo.Arguments = "-ssh -pw " & PASSWORD & " " & USERNAME & "@" & COMPUTERNAME & " rm ./" & UNIXSCRIPTNAME 
    Proc.StartInfo.RedirectStandardInput = True 
    Proc.StartInfo.RedirectStandardOutput = False 
    Proc.StartInfo.UseShellExecute = False 
    'Proc.StartInfo.CreateNoWindow = True 
    Proc.Start() 
    Proc.WaitForExit() 

이 단축 될 수 있는가? 나는 ... 유닉스 시스템 2) 만들기에 파일을 전송 1) 실행 3) 삭제 파일 (해당 스크립트) 4) 실행 후

답변

2

당신이 있는지 확인 할 수 있습니다 당신을 위해 일할 것입니다. 나는 그것을 검사 할 유닉스 시스템이 없지만 프로세스를 올바르게 채우는 것처럼 보인다. 또한 테스트 목적을 위해 변수의 기본값을 사용하지 않았습니다. 이렇게하면 많은 중복성이 제거되고 코드의 양이 줄어 듭니다.

Public Class Form1 
    Dim USERNAME As String = "USERNAME" 
    Dim COMPUTERNAME As String = "COMPUTERNAME" 
    Dim UNIXSCRIPTNAME As String = "UNIXSCRIPTNAME" 
    Dim PASSWORD As String = "PASSWORD" 
    Dim virtualFolder As String = "~/Scripts/" 
    Dim physicalFolder As String = "physicalFolder" 
    Dim unixLogin As String = (USERNAME & "@" & COMPUTERNAME & ":" & UNIXSCRIPTNAME) 
    Dim processCmdFileTransfer As String = "C:\pscp.exe -pw " & PASSWORD & " " & physicalFolder & "\" & UNIXSCRIPTNAME & " " & USERNAME & "@" & COMPUTERNAME & ":" & UNIXSCRIPTNAME 
    Dim processCmdFileActions As String = "-ssh -pw " & PASSWORD & " " & USERNAME & "@" & COMPUTERNAME & "XX" & UNIXSCRIPTNAME 

    Public Sub New() 

     ' This call is required by the designer. 
     InitializeComponent() 

     ' Add any initialization after the InitializeComponent() call. 
     test() 
    End Sub 

    Public Sub test() 

     RunProcess("C:\Windows\System32\cmd.exe", processCmdFileTransfer) 
     RunProcess("C:\plink.exe", processCmdFileActions, " chmod u+x ./") 
     RunProcess("C:\plink.exe", processCmdFileActions, " ./") 
     RunProcess("C:\plink.exe", processCmdFileActions, " rm ./") 

    End Sub 

    Private Sub RunProcess(processPath As String, startInfo As String, Optional command As String = "") 


     Dim Proc As New System.Diagnostics.Process 
     Proc.StartInfo = New ProcessStartInfo(processPath) 

     If (InStr(startInfo, "XX") > 0) And (command <> "") Then 
      startInfo = startInfo.Replace("XX", command) 
     End If 


     Proc.StartInfo.Arguments = startInfo 
     Proc.StartInfo.RedirectStandardInput = True 
     Proc.StartInfo.RedirectStandardOutput = False 
     Proc.StartInfo.UseShellExecute = False 
     Proc.Start() 
     Proc.WaitForExit() 

    End Sub 

최종 클래스

+0

내가 다시 주석하지 않은 죄송합니다. 나는 내일 직장에서 이것을보고 다시보고 할 것이다. – envinyater

+0

@envinyater 문제가없는 경우 알려주십시오. –

+0

매우 성공적이었습니다. 고맙습니다! – envinyater

관련 문제