我正在尝试通过Chrome扩展与Chrome "crosh“终端接口。我正在使用Secure的dev-id来访问chrome.terminalPrivate。从我最初的尝试中,我可以启动一个bash进程和bash。但是,我试图在~/Download目录中创建一个文件,但这似乎不起作用。据我所知,该文件从未创建过。
下面是我到目前为止收集的代码(我使用了来自Chromium的这个代码作为起点):
// 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);
}
谢谢你的帮忙!
https://stackoverflow.com/questions/47502621
复制相似问题