Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Can a function be exported to a subprocess?


Asked by Eugene McLean on Dec 12, 2021 FAQ



Functions are not exported to subprocesses. This is why there are files named .kshrc or .bashrc: To define functions that shoiuld be available in subshells also. If running a script, the .*shrc scripts are normally not sourced. You would have to code that explicitly, like in . ~/.kshrc.
Moreover,
If the subprocess is not imported, then as discussed earlier, no commands can be executed externally in Python codes, so to do this, we need to use subprocess modules.
Indeed, Subprocess function check_call () in Python This function runs the command (s) with the given arguments and waits for it to complete. Then it takes the return value of the code. If it is zero, it returns.
Likewise,
The input argument is passed to Popen.communicate () and thus to the subprocess’s stdin. If used it must be a byte sequence, or a string if encoding or errors is specified or universal_newlines is true. When used, the internal Popen object is automatically created with stdin=PIPE, and the stdin argument may not be used as well.
Furthermore,
If you need to "export" this variable over SSH, then you really need the function as a string. This can be done with the print option ( -p) for functions ( -f) of the declare built-in: