I want to execute a python program on a remote server, without creating a script. The remote server does not allow me to create any files anywhere on the file system.
The python program has following structure, though the functions are a lot more complicated
def test2():
print("test2")
def test_func():
test2()
print("test_func")
test_func()
Is there a way to execute this program directly from command line?
I have tried these 2 approaches
I get errors in both the cases. However, any code without user defined functions is able to execute with 2nd approach. Is it possible to get the code above working without creating a local script?
i found a solution, maybe it will help, you can use EOF
$ python << EOF
> def test2():
> print("test2")
>
> def test_func():
> test2()
> print("test_func")
>
> test_func()
> EOF
# output
test2
test_func
You can also use python -c with """
$ python -c """
def test2():
print("test2")
def test_func():
test2()
print("test_func")
test_func()
"""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With