Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run a process in background and get his pid ? #1595

Open
antkern opened this issue May 10, 2023 · 2 comments
Open

How to run a process in background and get his pid ? #1595

antkern opened this issue May 10, 2023 · 2 comments

Comments

@antkern
Copy link

antkern commented May 10, 2023

Hello

Is it possible to run a process in background and get is pid ?

The following code fails :

tshark -i lo -f udp & 
echo $! > PATH.PID

Thank you

@antkern
Copy link
Author

antkern commented May 10, 2023

Now i'm using a python code to bypass the problem

start_capture:
    #!/usr/bin/env python3
    import subprocess
    process = subprocess.Popen(["tshark", "-i", "lo", "-f", "udp"])
    with open("{{ CAPTURE_PATH }}.pid", "w") as out:
        out.write(str(process.pid))

@Taywee
Copy link

Taywee commented May 24, 2023

You can also use a shell shebang do bypass the problem.

In a normal Just recipe, each line is run in its own shell, so you can't refer to variables set in previous lines. Shebang recipes run the entire body through the selected interpreter. This should also work for you:

start_capture:
    #!/bin/sh
    tshark -i lo -f udp & 
    echo $! > PATH.PID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants