Jump to content

[HTML & JS] Run a python script in a terminal-like window

Go to solution Solved by straight_stewie,

Pyodide might be useful for you. It "compiles" to web assembly, but I believe it's really hacky. More than likely, to get good performance from running local languages natively in the browser, we will have to wait until web assembly is fairly mature, and offers many canonical language implementations.

An alternative is Jupyter Notebooks, which do require a server, but is specifically designed so that it can be set up to run locally only.

You could try to set up a web based SSH client in your browser, which would just connect back to to a local ssh server and allow you to do everything you can do directly from your machine. You could make things appear to be going on in a console window with some creative Javascript and CSS.

At the moment, all solutions but Pyodide are going to require you to run python in a server, it's just that a server doesn't actually have to be a server: You can run your server locally, and then just connect to it from your browser, in much the same manner that you do when working on a normal html/css/javascript client side site: This is one of the strong points behind Jupyter Notebooks: it was designed with this workflow in mind.

Be aware that you can run a server locally: i.e, on the same machine you are developing the client side stuff on. In order to do so, all you have to do is configure your server applications to run on your machine, and then configure your client applications to connect back to 127.0.0.1/WhateverPort.

4 minutes ago, WillLTT said:

i want to run a .py file in a terminal like window, kinda like repl.it, but without all the crap and mostly only the black terminal window.

 

Any help will be apprichiated! ?

That requires a whole framework on your server to do, you can't do it with just HTML and Javascript; the Python-script isn't running in your browser, it's actually running on the server and your browser just displays the script's output.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to post
Share on other sites

Just now, WereCatf said:

That requires a whole framework on your server to do, you can't do it with just HTML and Javascript; the Python-script isn't running in your browser, it's actually running on the server and your browser just displays the script's output.

crap.

i guess im hecked

Link to post
Share on other sites

51 minutes ago, WereCatf said:

That requires a whole framework on your server to do, you can't do it with just HTML and Javascript; the Python-script isn't running in your browser, it's actually running on the server and your browser just displays the script's output.

To be fair that could probably be made to work with a flask json API without too much hassle. Just send the code in the API request and return the code's output. Not very safe of course, but for a small personal project it could work. You could also have it run the script as an extremely unprivileged user to minimize potential damage to the host.

53 minutes ago, WillLTT said:

crap.

i guess im hecked

What do you need this for? There may be easier ways to go about it...

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to post
Share on other sites

2 minutes ago, Sauron said:

To be fair that could probably be made to work with a flask json API without too much hassle. Just send the code in the API request and return the code's output. Not very safe of course, but for a small personal project it could work. You could also have it run the script as an extremely unprivileged user to minimize potential damage to the host.

What do you need this for? There may be easier ways to go about it...

Flask is a framework, it doesn't run in the browser, so my point still stands; OP needs more than just HTML and Javascript running in the browser to do it. It could be done with Flask, Node.js, PHP or anything else, but the code to do that has to be running out-of-the-browser.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to post
Share on other sites

Why not run in an actually terminal and just install python? 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

58 minutes ago, vorticalbox said:

Beacuse its fun little project to make it work. 

 

1 hour ago, WereCatf said:

well, i cant do that beacause i have no server.

would it work with python's http.server module? 

Link to post
Share on other sites

Pyodide might be useful for you. It "compiles" to web assembly, but I believe it's really hacky. More than likely, to get good performance from running local languages natively in the browser, we will have to wait until web assembly is fairly mature, and offers many canonical language implementations.

An alternative is Jupyter Notebooks, which do require a server, but is specifically designed so that it can be set up to run locally only.

You could try to set up a web based SSH client in your browser, which would just connect back to to a local ssh server and allow you to do everything you can do directly from your machine. You could make things appear to be going on in a console window with some creative Javascript and CSS.

At the moment, all solutions but Pyodide are going to require you to run python in a server, it's just that a server doesn't actually have to be a server: You can run your server locally, and then just connect to it from your browser, in much the same manner that you do when working on a normal html/css/javascript client side site: This is one of the strong points behind Jupyter Notebooks: it was designed with this workflow in mind.

Be aware that you can run a server locally: i.e, on the same machine you are developing the client side stuff on. In order to do so, all you have to do is configure your server applications to run on your machine, and then configure your client applications to connect back to 127.0.0.1/WhateverPort.

ENCRYPTION IS NOT A CRIME

Link to post
Share on other sites

4 hours ago, WereCatf said:

Flask is a framework, it doesn't run in the browser, so my point still stands

Of course, I'm just saying it wouldn't be terribly hard.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×