Opening crosh and running a command

214 views
Skip to first unread message

John DeVries

unread,
Nov 25, 2017, 6:36:00 PM11/25/17
to chromiu...@chromium.org
Hi,

I'm attempting to add shortcut icons to my crouton'd Chromebook that will execute a command in the shell. Is there a way of having the crosh.html page execute my command on load? I've also tried manipulating crosh with Crosh.prototype in the console view. Perhaps, I could write my own extension that would message pass commands to crosh?

Thanks for your help,
John

Mike Frysinger

unread,
Nov 26, 2017, 11:33:20 AM11/26/17
to John DeVries, chromium-hterm
currently you cannot.  but i guess there's no reason we couldn't extend the "ssh command line" to support this.
-mike

--
You received this message because you are subscribed to the Google Groups "chromium-hterm" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-hterm/CAMbjhJ21gjEo4dR4VGAmo60pMC%2BP57%2Bk2t3%3D748HMu80CU6SgQ%40mail.gmail.com.

ledjoh...@gmail.com

unread,
Nov 27, 2017, 12:33:14 AM11/27/17
to chromium-hterm, ledjoh...@gmail.com
I was attempting to implement this as a proof of concept and I'm able to create the crosh terminal process with chrome.terminalPrivate.openTerminalProcess. I believe I'm starting the bash shell, but I don't think the command "touch ~/Downloads/test.txt" is run because the file isn't created. Is there anything special I'm missing? I'm using the Secure Shell dev-id to get access to the chrome.terminalPrivate class.

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

Mike Frysinger

unread,
Nov 29, 2017, 2:58:50 AM11/29/17
to John DeVries, chromium-hterm
it looks like you're trying to shoe horn a slow event driven process into a fast synchronous code path.  you need to change the model to react on events rather than shove input down the pipe when the other side isn't ready yet.

i.e. delete all the sendInput calls from openTerminalProcess and move all the logic to processListener.  that needs to check the output in "text" and then decide what to send next.

basically you need to implement an ad-hoc parser akin to expect.
-mike

katr...@gmail.com

unread,
Jan 28, 2018, 5:43:59 PM1/28/18
to chromium-hterm, ledjoh...@gmail.com
Less less Complicated Solution:
Replaces Crosh with Bash:
In the Shell:
cd /usr/bin;sudo sed -i.bak '' crosh;sudo sed -i '$ i exec /bin/bash --login "$@"' crosh
        After you can add anything in your /etc/bash/bashrc

Reply all
Reply to author
Forward
0 new messages