0

Problem with module "subproccess" in Kali-Linux Python3

I have this code: import subprocess as sp sp.call("echo 1 > /proc/sys/net/ipv4/ip_forward") after execution I have next problem: raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'echo 1 > /proc/sys/net/ipv4/ip_forward' . BUT if I call this command in cmd line it works! I want this to work in the python script. Please help!

22nd Mar 2021, 3:41 PM
Андрей Пермяков
Андрей Пермяков - avatar
7 ответов
+ 1
Since its just one string you pass to the function, add the parameter: shell=True. # like sp.call("echo 1 > /proc....", shell=True)
23rd Mar 2021, 8:41 AM
Slick
Slick - avatar
+ 1
Slick ,thank you very much! It works without any errors
25th Mar 2021, 7:39 AM
Андрей Пермяков
Андрей Пермяков - avatar
0
Slick, thank you, I'll check it out. But could you explain what this parameter does?
23rd Mar 2021, 9:34 AM
Андрей Пермяков
Андрей Пермяков - avatar
0
nope, cause i don't know. it was easily found through a google search though Андрей Пермяков https://www.pythonforbeginners.com/os/subprocess-for-system-administrators/
23rd Mar 2021, 10:42 AM
Slick
Slick - avatar
0
Slick ,well I didn't
23rd Mar 2021, 1:37 PM
Андрей Пермяков
Андрей Пермяков - avatar
0
search or finf it?
23rd Mar 2021, 1:41 PM
Slick
Slick - avatar
0
Niiice, no problem at all! Oh, and Андрей Пермяков , a warning. Keep that code to yourself. Using the shell=True parameter allows for arbiturary code to be ran in your shell wich has big potential damage to your system. (as long as it's just you, you'll be fine) Just be careful who you let around this one and I wouldn't delete anything, it WILL work haha
25th Mar 2021, 7:40 AM
Slick
Slick - avatar