1

Chrome 확장 프로그램을 통해 Chrome OS 'crosh'터미널과의 인터페이스를 시도하고 있습니다. Secure Shell의 dev-id를 사용하여 chrome.terminalPrivate에 액세스합니다. 나의 처음 시도에서, 나는 크로스 프로세스와 bash 쉘을 시작할 수있다. 그러나 ~/Downloads 디렉토리에 파일을 만들려고하는데 작동하지 않는 것 같습니다. 내가 말할 수있는 한 파일은 결코 생성되지 않는다.Chrome 확장 프로그램의 크로스를 사용하여 파일 만들기 [terminalPrivate.sendInput]

가 여기에 지금까지 조립 한 코드입니다 (나는 출발점으로 크롬 개발자에서이 code을 사용) :

// Copyright (c) 2012 The Chromium Authors. All rights reserved. 
// Use of this source code is governed by a BSD-style license that can be 
// found in the LICENSE file. 

var shellCommand = 'shell\n'; 
var croshName = 'crosh'; 

window.onload = function() { 
    Crosh(null); 
    commandTest(); 
} 

function Crosh(argv) { 
    this.argv_ = argv; 
    this.io = null; 
    this.keyboard_ = false; 
    this.pid_ = -1; 
} 

function commandTest() { 
    chrome.terminalPrivate.onProcessOutput.addListener(processListener); 

    chrome.terminalPrivate.openTerminalProcess(croshName, (pid) => { 
    if (pid < 0) { 
     window.alert("error!"); 
    } 

    this.pid_ = pid; 

    var cmd1 = 'shell\n'; 
    var cmd2 = 'touch ~/Downloads/test.txt\n'; 

    chrome.terminalPrivate.sendInput(pid, cmd1, 
     function (r1) { 
     window.alert(r1); 
     } 
    ); 

    chrome.terminalPrivate.sendInput(pid, cmd2, 
     function (r2) { 
     window.alert(r2); 
     } 
    ); 

    chrome.terminalPrivate.closeTerminalProcess(
     this.pid_, 
     function(result) { 
     window.alert(result); 
     } 
    ); 
    }); 
} 

function processListener(pid, type, text){ 
    window.alert(text); 
} 

감사를 도와! 당신이 빠른 동기 코드 경로에 느린 이벤트 기반 프로세스 혼 슈에 노력하고있는 것처럼

답변

0

난 당신이이 질문을 게시 chromium-hterm group에 대답도

것 같습니다. 다른 쪽이 아직 준비되지 않았을 때 파이프를 아래로 밀어 넣는 대신 이벤트에 반응하도록 모델을 변경해야합니다.

즉 openTerminalProcess에서 모든 sendInput 호출을 삭제하고 모든 논리를 processListener로 이동합니다. "텍스트"로 출력을 확인한 후 다음에 보낼 내용을 결정해야합니다.

기본적으로 expect과 비슷한 임시 파서를 구현해야합니다.

관련 문제