2009-12-09 5 views
1

안녕하세요, 저는 델파이 응용 프로그램에서 일하고 있습니다. 로컬 컴퓨터에서 델파이 응용 프로그램의 원격 컴퓨터에있는 펄 스크립트를 실행해야합니다. 수동 처리없이이 프로세스를 자동으로 수행해야합니다. 지금 나는 펄 스크립트를 실행하기 위해 현재 프로세스를 명확하게 설명 할 것이고, 나는 퍼티 윈도우를 열고, 원격 머신에 연결하고 펄 스크립트를 실행할 것이다. perl 스크립트는 차례로 저장 프로 시저를 호출하고 테이블을 업데이트합니다.delphi 응용 프로그램에서 원격 컴퓨터의 펄 스크립트를 실행하는 방법은 무엇입니까?

이제 버튼을 클릭하여 위에서 설명한 과정을 자동으로 수행하고 싶습니다. 따라서 버튼을 클릭하면 원격 컴퓨터에 연결 한 다음 펄 스크립트를 실행하는 함수를 호출해야합니다. 내가 너에게 명확한가 ??? 이 문제를 해결하는 데 도움주세요. 델파이에서 가능한 한 빨리이 코드가 필요합니다.

+0

그냥 수동으로 수행하는 작업을 자동화하십시오. –

+0

어떤 부분에 문제가 있습니까? 원격 컴퓨터에 연결하거나, 프로그램을 실행하거나, * Perl 스크립트 *를 실행하고 있습니까? –

답변

2

두 단계 :

  • 실행 펄 스크립트를 SSH를 할 수있는 델파이 모듈/기능을 사용합니다.
+0

은 그러한 모듈에 대한 링크를 게시하면 좋습니다. – NickSoft

0

너는 Capistrano을 들여다 볼 수 있는데, 정확하게 이런 종류의 자동화를 위해 설계되었습니다. 당신은 단지에 있어야한다 :

  1. download을 및 Windows
  2. 에 대한
  3. download을 루비를 설치하고 설치 젬
  4. 펄 스크립트를 호출하는 카피 스트라 노 조리법을 만들 원격
  5. 델파이 응용 프로그램에서 카피 스트라 노를 호출
-1

나는 Perl을 모른다. 하지만 내가 올바르게 이해한다면 그것은 PHP와 비슷한 웹 스크립팅 언어입니다. 나도 PHP와 비슷한 상황에 직면했다. 그래서 PHP 스크립트 내 델파이 애플 리케이션 내에서 인디를 사용하여 전화를 끝내고. 동일한 종류의 로직이 perl에 적용될 수 있는지 여부는 알 수 없습니다. 다음은 논리의 일부입니다.

var 
    IdHTTP: TIdHTTP; 
    IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocketOpenSSL; 
begin 
    try 
    IdSSLIOHandlerSocket1 := TIdSSLIOHandlerSocketOpenSSL.create(nil); 
    IdHTTP := TIdHTTP.create(nil); 
    idhttp.handleredirects := True; 
    with IdSSLIOHandlerSocket1 do begin 
     SSLOptions.Method := sslvSSLv3; 
     SSLOptions.Mode := sslmUnassigned; 
     SSLOptions.VerifyMode := []; 
     SSLOptions.VerifyDepth := 2; 
    end; 
    with IdHTTP do begin 
     IOHandler := IdSSLIOHandlerSocket1; 
     ProxyParams.BasicAuthentication := False; 
     Request.ContentType := 'text/html'; 
     request.connection := 'keep-alive'; 
     Request.Accept := 'text/html, */*'; 
    end; 
    result := idhttp.get('http://www.mysite.com/myscript.php'); 
    finally 
    IdHTTP.free; 
    IdSSLIOHandlerSocket1.free; 
    end; 
end; 
+0

Perl은 웹 스크립팅 언어가 아닙니다. "펄은 높은 수준의 범용 해석 언어이며 동적 프로그래밍 언어입니다." (http://en.wikipedia.org/wiki/Perl) - Perl로 웹 응용 프로그램을 작성할 수 있지만 모든 Perl 스크립트가 웹 응용 프로그램이 아닙니다. – mjn

+0

모든 답장을 보내 주셔서 감사합니다. 이 자동화 프로세스를 완료하면 알려 드리겠습니다. 고마워. 다른 솔루션을 가지고 있다면 나와 공유하십시오. – JVNR

0

원격 컴퓨터에서 Windows를 실행하는 경우 PsExec이 해결책이 될 수 있습니다.

PsExec를 사용하면 다른 시스템

에 프로세스를 실행 할 수있는 경량 텔넷 대체

원격

0

인가 Windows 호스트에서 프로그램을 실행 WinExe 같은 유사한 도구가 있습니다 Windows를 실행하는 원격 컴퓨터? 그렇다면 델파이에서 항상 "psexec"를 호출 할 수 있습니다. 또는 WMI를 사용하여 프로세스를 원격으로 실행할 수 있습니다 (원격 호스트에서 일부 Windows 버전을 실행한다고 가정)

여기에 Delphi의 전체 예제 taken from here이 있습니다. Delphi 2007에서 "구성 요소 가져 오기 | 형식 라이브러리 가져 오기"메뉴 옵션을 사용하여 % windir % \ System32 \ wbem \ wbemdisp.tlb 유형 라이브러리를 설치하여 만들 수있는 WbemScripting_TLB 단위가 필요합니다.

unit Unit1; 

interface 

uses 
    Windows, 
    Messages, 
    SysUtils, 
    Variants, 
    Classes, 
    Graphics, 
    Controls, 
    Forms, 
    Dialogs, 
    StdCtrls, 
    ComCtrls; 

type 
    TForm1 = class(TForm) 
    btnExecute: TButton; 
    edtProgramToExecute: TEdit; 
    Label2: TLabel; 
    Label3: TLabel; 
    Label4: TLabel; 
    Label5: TLabel; 
    edtRemoteMachine: TEdit; 
    edtUser: TEdit; 
    edtPassword: TEdit; 
    procedure btnExecuteClick(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.dfm} 

uses WbemScripting_TLB; 

function remoteExecute(programName: string; machine: string = ''; user: string = ''; 
    password: string = ''): string; 
var 
    SWbemLocator1: TSWbemLocator; 
    Service: ISWbemServices; 
    InParam, 
    OutParam, SObject: ISWbemObject; 
    Method: ISWbemMethod; 
    SProp1 
    , SProp2, MyProperty 
    : ISWbemProperty; 
    s, methodName: string; 
    PropValue: OleVariant; 
begin 
    methodName := 'Create'; 
    // CoInitialize(nil); 
    SWbemLocator1 := TSWbemLocator.Create(nil); 
    if machine = '' then 
    machine := '.'; 
    Service := SWbemLocator1.ConnectServer(machine, 'root\CIMV2', user, password, '', '', 
    0, nil); 
    Service.Security_.Set_ImpersonationLevel(wbemImpersonationLevelImpersonate); 
    SObject := Service.Get('Win32_Process', 0, nil); 

    Method := SOBject.Methods_.Item(methodName, 0); 
    InParam := Method.InParameters.SpawnInstance_(0); 

    MyProperty := InParam.Properties_.Add('CommandLine', wbemCimtypeString, False, 0); 
    PropValue := programName; 
    MyProperty.Set_Value(PropValue); 

    MyProperty := InParam.Properties_.Add('CurrentDirectory', wbemCimtypeString, False, 0); 
    PropValue := Null; 
    MyProperty.Set_Value(PropValue); 

    MyProperty := InParam.Properties_.Add('ProcessStartupInformation', wbemCimtypeObject, 
    False, 0); 
    PropValue := Null; 
    MyProperty.Set_Value(PropValue); 

    OutParam := SObject.ExecMethod_(methodName, InParam, 0, nil); 
    // OutParam:= SObject.ExecMethod_(methodName, nil, 0, nil); 
    SProp1 := outParam.Properties_.Item('ReturnValue', 0); 
    SProp2 := outParam.Properties_.Item('ProcessId', 0); 
    case SProp1.Get_Value of 
    0: s := 'Successful completion.'; 
    2: s := 'Access denied.'; 
    3: s := 'Insufficient privilege.'; 
    8: s := 'Unknown failure.'; 
    9: s := 'Path not found.'; 
    21: s := 'Invalid parameter.'; 
    else 
    s := 'Unknown reply code!'; 
    end; 
    SWbemLocator1.Free; 
    service := nil; 
    SObject := nil; 
    OutParam := nil; 
    SProp1 := nil; 
    result := s + '(PID=' + inttostr(SProp2.Get_Value) + ')'; 
    // CoUninitialize; 
end; 

procedure TForm1.btnExecuteClick(Sender: TObject); 
begin 
    statusbar1.simpletext := remoteExecute(edit1.text, edit2.text, edit3.text, edit4.text); 
end; 

end. 

또한 VBScript로이 작업을 수행 할 수 있습니다 당신은 이미 수동으로 무엇을 자동화의 정신

Here's a VBScript snippet that demonstrates how this would work. 
' This script provides a function for executing a command on a remote computer 
' This uses WMI and requires that you have administrative righs on the remote machine 
' 

Dim strComputer, strCommandLineToRun 

'change the period to an IP Address or computer name 
strComputer = "." 'example: strComputer = "192.168.1.105" 

'this is the path to the file on the computer whose name/IP address is stored in the strComputer variable 
strCommandLineToRun = "c:\windows\system32\calc.exe" 


' This calls the function to run the process on a remote computer 
RemoteExecute strComputer,"","",strCommandLineToRun 


Function RemoteExecute(strServer, strUser, strPassword, CmdLine) 
    Const Impersonate = 3 

    RemoteExecute = -1 

    Set Locator = CreateObject("WbemScripting.SWbemLocator") 
    Set Service = Locator.ConnectServer(strServer, "root\cimv2", strUser, strPassword) 

    Service.Security_.ImpersonationLevel = Impersonate 
    Set Process = Service.Get("Win32_Process") 

    result = Process.Create(CmdLine, , , ProcessId) 

    If (result <> 0) Then 
     WScript.Echo "Creating Remote Process Failed: " & result 
     Wscript.Quit 
    End If 

    RemoteExecute = ProcessId 
End Function 
3

, 당신은 퍼티와 함께 ​​제공되는 Plink 유틸리티를 사용할 수 있습니다. 실행할 사용자 이름, 호스트, 암호 및 명령을 포함하여 다양한 명령 줄 옵션을 사용할 수 있습니다. 저장된 퍼티 세션에서도 대부분의 옵션을 지정할 수 있습니다. 자세한 내용은 the Putty documentation을 참조하십시오. CreateProcess을 사용하여 프로그램에서 명령을 실행할 수 있습니다.

var 
    cmd: string; 
begin 
    cmd := 'plink -batch -ssh -pw secret [email protected] /home/user/command.pl'; 
    UniqueString(cmd); 
    CreateProcess(nil, PChar(cmd), ...); 

실행해야하는 명령에 매개 변수가있는 경우 전체 명령을 인용해야 할 수 있습니다. 실행할 명령이 여러 개인 경우 파일에 넣은 다음 Plink의 -m 옵션을 사용해야합니다.

+0

답장을 보내 주셔서 감사합니다. 내 응용 프로그램에서 이것을 구현하고 내가이 문제에 직면하면 알려 주시기 바랍니다. – JVNR

관련 문제