Curl domain and run script

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.

1 Like

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!"
1 Like

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!"
});
1 Like

No… Bash and python I can do. No idea about node

Hmm, ok, I’ll look into a way to do this in python.

1 Like

Try this:

import os
myCmd = 'python3 hello.py'
os.system(myCmd) # outputs "hi!"
1 Like

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
3 Likes

yeah… it could work…

i’ve accepted @ihack2712’s solution, thanks all!

1 Like

Then why don’t you mark @ihack2712’s post as Solution? :joy:

3 Likes

lol :laughing: ,

goes to change everything