Say I have a python script, how would I get that to run when the domain is curled?
curl name.glitch.me
hi!
test.py
print("hi!")
Say I have a python script, how would I get that to run when the domain is curled?
curl name.glitch.me
hi!
test.py
print("hi!")
You want curl name.glitch.me
to print hi!
or whatever the one who curled?
In that case you need to use a webserver.
Would flask work?
What you would want to do is use a command to run shell commands of the terminal.
You would first have to have the hello.py file on the website. Then you would need some code like this:
<?php
// php
echo exec("python3 hello.py"); // output would be "hi!"
Okay, but i’m not really sure about using PHP…
Is there any other methods available?
Would node work for you?
const { exec } = require("child_process");
exec("python3 hello.py", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`); // "hi!"
});
No… Bash and python I can do. No idea about node
Hmm, ok, I’ll look into a way to do this in python.
Try this:
import os
myCmd = 'python3 hello.py'
os.system(myCmd) # outputs "hi!"
Thanks, let me elaborate…
I want the user to curl the domain, and something should direct them to the running script. I could try with flask but is there any other way?
What do you mean? Do you mean the script should run on their local machine?
It should run on their machine without download. Which is possible with command line flags but are inconvenient…
Ah, you could just serve the python file in a static file server, then when the user curls the file you could do something like this:
curl https://name.glitch.me/file.py | python3
yeah… it could work…
lol ,
goes to change everything