0

I want to know how to open a Terminal shell from JavaScript and then write to the command line (this would be on a dedicated server).

I have looked at using ActiveX but found that this can only be used on Windows and Internet Explorer.

The complete function I want to implement is firstly to open up a Terminal shell, open a standalone instance of Maya, run my Python script and save the Maya scene.

I want this all to run in the background after clicking the 'Export' button in my Three.js scene. Hence the reason for me wanting to be able to run the command line from my JavaScript code.

skelto
  • 157
  • 1
  • 11
  • 1
    It’s not possible to start other programs from JavaScript code alone, except if you find some security hole. – Sebastian Simon Jun 08 '16 at 16:17
  • This doesn't make sense. If you intend to open a Terminal window locally, that cannot be done. If you intend to open a Terminal for the server, that is even more impossible. – durbnpoisn Jun 08 '16 at 16:19
  • Imagine any webpage you visit could open your command line and run whatever command it liked... Are you picturing your system in a burning mess? That's why you can't control the command line from JS. – DBS Jun 08 '16 at 16:30
  • @DBS I would look to send a command to a server that would then open the application. – skelto Jun 08 '16 at 16:32
  • You could absolutely send an AJAX request to some server side code, but that's very different to opening a command line locally with JS. But then it would be the server side code executing the operation, not the clients JS. – DBS Jun 08 '16 at 16:34

4 Answers4

0

You can't with pure javascript as it's a security issue. ActiveX was a huge failure and is essentially deprecated for it's major security flaws (IE has a hardcoded whitelist of sites that can use ActiveX).

To do anything remotely like this you'l need to write a chrome extension plugin where javascript calls methods to out-of-browser processes.

Edit: From the other answer it looks like the tools that make that possible are deprecated as well. Maybe if you describe the nature of the application we can help you find a different solution. To do something like this you probably need a local rest server/service running.

micah
  • 7,596
  • 10
  • 49
  • 90
  • Can you point to a resource suggesting that Chrome extension can run something like the Terminal? Because [this question's answers](http://stackoverflow.com/questions/2652094/start-an-external-application-from-a-google-chrome-extension) say it can't. – T.J. Crowder Jun 08 '16 at 16:21
  • I have updated my question to better describe my intentions. The application will be run on a dedicated server in the future, at the minute I am using AMPPS for development purposes. – skelto Jun 08 '16 at 16:30
0

JavaScript code in a normal web page or web app cannot, fpr presumably obvious security reasons, reach out and run arbitrary executables on your workstation.

Chrome's extensions cannot run local executables either.

FireBreath won't be useful to you because Chrome is actively removing support for NPAPI (it's already removed on Linux, don't know about Mac OS X) and never — quite correctly — supported ActiveX.

Fundamentally, you need to go a different direction. Perhaps an app framework for Mac OSX that supports using HTML and CSS and JavaScript to build the app, so that it's a full app, not something hosted within the browser. If you search for "build OSX app in JavaScript and HTML" you'll find several solutions, for instance (as of this writing) AppJS or Sentenza — but those are just examples, not recommendations.


From your edit, what I'd do is write a server piece in NodeJS (with or without ExpressJS), and have the browser page send an ajax request to the server, which can spawn the processes you want it to spawn.

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Is there any way at all that I could go about implementing the desired functionality of being able to run an application from JavaScript or is this a dead end? I've revised my question to explain my intentions more clearly. – skelto Jun 08 '16 at 16:27
  • @skelto: From *JavaScript*, yes, as I outlined at the end of my answer. From JavaScript *in Chrome*, no, none that I'm aware of. – T.J. Crowder Jun 08 '16 at 16:35
  • @skelto: Having seen your edit, I've added a note to the end of the answer as well. – T.J. Crowder Jun 08 '16 at 16:36
0

Look at uri schemes. It is possible but with a bit more steps. Uri schemes is how the a computer knows what to do with urls like http//: or file//:

I got the idea from iTunes so you could take a look at their uri scheme if you can find it. If you go to the iTunes Store in a web browser and if iTunes is installed(recently ice found it to be broken) it will say open in iTunes and generates a url that will open iTunes with specific arguments

cronicryo
  • 437
  • 1
  • 4
  • 15
  • I've been able to open a standalone version of Maya from a PHP script, by using the exec() function to send commands to the Terminal. I need to then run a Python script in Maya. I went down the route of opening a Maya Python interpreter in the Terminal. Although once I have the Python interpreter running in the Terminal I have not been able to send anymore commands. Would you know anything about sending commands to a Terminal running a Python interpreter? – skelto Jun 23 '16 at 13:17
  • This may need to be asked in a new question, but I thought I'd ask you in case you knew something about it. – skelto Jun 23 '16 at 13:18
  • What's your backend? – cronicryo Jun 23 '16 at 16:40
-1

To run terminal from javascript used in Chrome , From Tab Menu, Click More Tools --->Developers tools and then select console Tab

Joel Wembo
  • 814
  • 6
  • 10