popen

LD_PRELOAD affects new child even after unsetenv(“LD_PRELOAD”)

♀尐吖头ヾ 提交于 2019-12-18 16:39:06
问题 my code is as follows: preload.c, with the following content: #include <stdio.h> #include <stdlib.h> int __attribute__((constructor)) main_init(void) { printf("Unsetting LD_PRELOAD: %x\n",unsetenv("LD_PRELOAD")); FILE *fp = popen("ls", "r"); pclose(fp); } then in the shell (do the 2nd command with care!!): gcc preload.c -shared -Wl,-soname,mylib -o mylib.so -fPIC LD_PRELOAD=./mylib.so bash !!! be carefull with the last command it will result with endless loop of forking "sh -c ls". Stop it

c: catch a segfault in exec() which was run in a child process

こ雲淡風輕ζ 提交于 2019-12-18 13:42:11
问题 EDIT: I am trying to write a simple smoketest, where all options and reasonable parameters are tested. I used popen() to execute the program that should be tested. Using this approach does not work, because if the process dies with a signal (SIGINT, SIGSEGV...) the pipe from popen() does not tell me what happend. Writing a signal handler did not help since popen creates a new process that receives the signals but not my smoketest. Thanks to the answers i used pipe(), fork() and execv() to

Python: executing shell script with arguments(variable), but argument is not read in shell script

旧时模样 提交于 2019-12-18 13:01:22
问题 I am trying to execute a shell script(not command) from python: main.py ------- from subprocess import Popen Process=Popen(['./childdir/execute.sh',str(var1),str(var2)],shell=True) execute.sh ---------- echo $1 //does not print anything echo $2 //does not print anything var1 and var2 are some string that I am using as an input to shell script. Am I missing something or is there another way to do it? Referred: How to use subprocess popen Python 回答1: The problem is with shell=True . Either

Python: executing shell script with arguments(variable), but argument is not read in shell script

巧了我就是萌 提交于 2019-12-18 13:01:02
问题 I am trying to execute a shell script(not command) from python: main.py ------- from subprocess import Popen Process=Popen(['./childdir/execute.sh',str(var1),str(var2)],shell=True) execute.sh ---------- echo $1 //does not print anything echo $2 //does not print anything var1 and var2 are some string that I am using as an input to shell script. Am I missing something or is there another way to do it? Referred: How to use subprocess popen Python 回答1: The problem is with shell=True . Either

Python - Launch a Long Running Process from a Web App

拜拜、爱过 提交于 2019-12-18 12:35:18
问题 I have a python web application that needs to launch a long running process. The catch is I don't want it to wait around for the process to finish. Just launch and finish. I'm running on windows XP, and the web app is running under IIS (if that matters). So far I tried popen but that didn't seem to work. It waited until the child process finished. 回答1: Ok, I finally figured this out! This seems to work: from subprocess import Popen from win32process import DETACHED_PROCESS pid = Popen(["C:

Python Popen - wait vs communicate vs CalledProcessError

强颜欢笑 提交于 2019-12-18 11:13:38
问题 Continuing from my previous question I see that to get the error code of a process I spawned via Popen in python I have to call either wait() or communicate() (which can be used to access the Popen stdout and stderr attributes): app7z = '/path/to/7z.exe' command = [app7z, 'a', dstFile.temp, "-y", "-r", os.path.join(src.Dir, '*')] process = Popen(command, stdout=PIPE, startupinfo=startupinfo) out = process.stdout regCompressMatch = re.compile('Compressing\s+(.+)').match regErrMatch = re

io.popen - how to wait for process to finish in Lua?

拈花ヽ惹草 提交于 2019-12-18 07:36:23
问题 I have to use io.popen in Lua to run an executable which takes a command line argument. How to wait for a process to finish in the Lua so that expected output can be captured? local command = "C:\Program Files\XYZ.exe /all" hOutput = io.popen(command) print(string.format(""%s", hOutput)) Suppose the executable is XYZ.exe which needs to be called with command line argument /all . Once io.popen(command) gets executed, the process will return some string which needs to be printed. My code

Why does manage.py execution script run twice when using it under if __name__ == “__main__”

亡梦爱人 提交于 2019-12-18 07:06:21
问题 Goal. When launching django framework also launch other PY scripts that rely on django objects. Get the server and port number from a config file. Problem: The Popen seems to run twice and I'm not sure why? #!/usr/bin/env python import os import sys import subprocess os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test.localsettings") from django.core.management import execute_from_command_line def getargs(): try: f = open("config") data = [] for line in f: data.append(line) f.close() server

Ruby pipes: How do I tie the output of two subprocesses together?

谁说胖子不能爱 提交于 2019-12-18 03:55:29
问题 Is there an automated way to do shell piping in Ruby? I'm trying to convert the following shell code to Ruby: a | b | c... > ... but the only solution I have found so far is to do the buffer management myself (simplified, untested, hope it gets my meaning across): a = IO.popen('a') b = IO.popen('b', 'w+') Thread.new(a, b) { |in, out| out.write(in.readpartial(4096)) until in.eof? out.close_write } # deal with b.read... I guess what I'm looking for is a way to tell popen to use an existing

Python subprocess Popen.communicate() equivalent to Popen.stdout.read()?

…衆ロ難τιáo~ 提交于 2019-12-17 22:09:34
问题 Very specific question (I hope): What are the differences between the following three codes? (I expect it to be only that the first does not wait for the child process to be finished, while the second and third ones do. But I need to be sure this is the only difference...) I also welcome other remarks/suggestions (though I'm already well aware of the shell=True dangers and cross-platform limitations) Note that I already read Python subprocess interaction, why does my process work with Popen