#πŸ”’ When spawning a subprocess, I get permission denied. This is on macOS

33 messages Β· Page 1 of 1 (latest)

brisk stirrup
#

I am attempting to create a child process that kills the parent process, and then it ends itself. Currently, I am stuck on spawning the subprocess. Is there something I should/not be doing?
File: /main.py

def start_updater() -> None:
  subprocess.run("<path>/update/main.py", input=f"{os.getpid()}")

def main() -> None:
  start_updater()

File: /update/main.py

import sys
with open("<path>/update/input.txt", 'w') as file:
  for line in sys.stdin:
    file.write(f"{line}")
    break # Only will receive one line: the PID
arctic socketBOT
#

@brisk stirrup

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

brisk stirrup
lone crown
#

hi

#

chmod +x <path/.py>

brisk stirrup
brisk stirrup
split creek
#

You can't directly run a python file IIRC

#

you have to run the interpreter with the python file as an argument

lone crown
#

the next step is making sure your script starts with
#!/usr/bin/env python3

then your subprocess.run() call would work

lone crown
#

hm

brisk stirrup
lone crown
brisk stirrup
#

ah okay, will do that now, thanks

brisk stirrup
lone crown
#

if i recall correctly

lone crown
#

if it doesnt work, sure we can try that interpreter way
subprocess.run(["python3", "your_path/something/temp.py"])

brisk stirrup
#

It has worked, just the way i'm writing to the file is wrong (working on it)

#

So i wanted to fix that then say "it works"

#

oh actually wrong file

#

bytes object in sending the input to the subprocess

brisk stirrup
#

It now works (found a number in the input.txt file)
Thanks @lone crown :3

#

Also, is there a way to give execution permission within code? (this is for a game designed to be distributed to users who don't program at all)
I'm using auto-py-to-exe to collect everything and create one executable (/main.py), so maybe that helps?

lone crown
#

i know there is a chmod method in the os library

#

but you may need to test it a bit - i am not sure if there will be any security/permissions problems (have not used that much)

brisk stirrup
#

Okay thanks!

#

!close

arctic socketBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.