Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 使用Chrome扩展名[terminalPrivate.sendInput]中的crosh创建文件_Bash_Google Chrome_Google Chrome Extension_Google Chrome App_Crosh - Fatal编程技术网

Bash 使用Chrome扩展名[terminalPrivate.sendInput]中的crosh创建文件

Bash 使用Chrome扩展名[terminalPrivate.sendInput]中的crosh创建文件,bash,google-chrome,google-chrome-extension,google-chrome-app,crosh,Bash,Google Chrome,Google Chrome Extension,Google Chrome App,Crosh,我正试图通过一个Chrome扩展与Chrome OS“crosh”终端接口。我正在使用Secure Shell的开发id访问chrome.terminalPrivate。从我最初的尝试开始,我能够启动crosh进程和bashshell。但是,我正在尝试在~/Downloads目录中创建一个文件,但这似乎不起作用。据我所知,该文件从未创建过 以下是我到目前为止编写的代码(我从Chromium开发人员那里使用它作为起点): //版权所有(c)2012 Chromium作者。版权所有。 //此源代码的

我正试图通过一个Chrome扩展与Chrome OS“crosh”终端接口。我正在使用Secure Shell的开发id访问chrome.terminalPrivate。从我最初的尝试开始,我能够启动crosh进程和bashshell。但是,我正在尝试在~/Downloads目录中创建一个文件,但这似乎不起作用。据我所知,该文件从未创建过

以下是我到目前为止编写的代码(我从Chromium开发人员那里使用它作为起点):

//版权所有(c)2012 Chromium作者。版权所有。
//此源代码的使用受BSD样式许可证的约束,该许可证可以
//在许可证文件中找到。
var shellCommand='shell\n';
变量croshName='crosh';
window.onload=函数(){
克罗什(空);
命令测试();
}
函数Crosh(argv){
this.argv=argv;
this.io=null;
this.keyboard=false;
this.pid=-1;
}
函数commandTest(){
chrome.terminalPrivate.onProcessOutput.addListener(processListener);
chrome.terminalPrivate.openTerminalProcess(croshName,(pid)=>{
if(pid<0){
window.alert(“错误!”);
}
this.pid=pid;
var cmd1='shell\n';
var cmd2='touch~/Downloads/test.txt\n';
chrome.terminalPrivate.sendInput(pid、cmd1、,
功能(r1){
窗口警报(r1);
}
);
chrome.terminalPrivate.sendInput(pid、cmd2、,
功能(r2){
窗口警报(r2);
}
);
铬.终端私盐.封闭终端工艺(
这个,这个,,
功能(结果){
窗口。警报(结果);
}
);
});
}
函数processListener(pid、类型、文本){
窗口警报(文本);
}
谢谢你的帮助

我也在你发布的地方回答了这个问题

看起来您正试图将一个缓慢的事件驱动流程引导到一个快速的同步代码路径中。您需要更改模型以对事件作出反应,而不是在另一方尚未准备好时将输入推下管道

i、 e.从openTerminalProcess删除所有sendInput调用,并将所有逻辑移到processListener。这需要检查“文本”中的输出,然后决定下一步发送什么

基本上,您需要实现一个类似于的特殊解析器。

我在您发布这个问题的地方也回答了这个问题

看起来您正试图将一个缓慢的事件驱动流程引导到一个快速的同步代码路径中。您需要更改模型以对事件作出反应,而不是在另一方尚未准备好时将输入推下管道

i、 e.从openTerminalProcess删除所有sendInput调用,并将所有逻辑移到processListener。这需要检查“文本”中的输出,然后决定下一步发送什么

基本上,您需要实现一个类似于的特殊解析器

// 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);
}