exec

How print every line of a python script as its being executed (including the console)?

浪子不回头ぞ 提交于 2021-02-20 17:55:23
问题 I'd like to print every line of python script as it's being executed, as well as the log from the console as every line is being executed. For example, for this script: import time print 'hello' time.sleep(3) print 'goodbye' I'd like it to generate the following in the console: line 1: import time line 2: print 'hello' hello line 3: time.sleep(3) line 4: print 'goodbye' goodbye See below for my attempt import subprocess as subp python_string = """ import sys import inspect class SetTrace

How print every line of a python script as its being executed (including the console)?

浪子不回头ぞ 提交于 2021-02-20 17:55:02
问题 I'd like to print every line of python script as it's being executed, as well as the log from the console as every line is being executed. For example, for this script: import time print 'hello' time.sleep(3) print 'goodbye' I'd like it to generate the following in the console: line 1: import time line 2: print 'hello' hello line 3: time.sleep(3) line 4: print 'goodbye' goodbye See below for my attempt import subprocess as subp python_string = """ import sys import inspect class SetTrace

How print every line of a python script as its being executed (including the console)?

旧城冷巷雨未停 提交于 2021-02-20 17:54:14
问题 I'd like to print every line of python script as it's being executed, as well as the log from the console as every line is being executed. For example, for this script: import time print 'hello' time.sleep(3) print 'goodbye' I'd like it to generate the following in the console: line 1: import time line 2: print 'hello' hello line 3: time.sleep(3) line 4: print 'goodbye' goodbye See below for my attempt import subprocess as subp python_string = """ import sys import inspect class SetTrace

Laravel hangs when running command via exec without sending it to background

你。 提交于 2021-02-17 06:34:07
问题 I have a weird issue that I've been stuck with for a couple of days now. I'm trying to generate a pdf in a Laravel app using chrome headless with this command google-chrome --headless --disable-gpu --print-to-pdf=outputfile.pdf http://localurl/pdf-html The command basically opens chrome in headless mode, navigates to the given url and prints it as pdf saving the file in the specified location. This command is working perfectly when run in my system's shell (I'm using Ubuntu 18.04). Now, my

Using execv to do basic I/O

风流意气都作罢 提交于 2021-02-11 18:10:45
问题 I'm trying to use execv() to allow me to read into an output file, outputfile.txt, from the terminal. The problem I'm having is that it won't work at all and I don't know if I'm using it correctly. My code so far: void my_shell() { char* args[2]; args[0] = "/usr/bin/tee"; args[1] = "outputfile.txt"; execv(args[0], &args[0]); } int main() { cout << "%"; //string input; pid_t pid, waitPID; int status = 0; pid = fork(); if (pid == 0) { my_shell(); } else if (pid < 0) { cout << "Unable to fork" <

Running a Python script from PHP

。_饼干妹妹 提交于 2021-02-11 16:57:01
问题 I'm trying to run a Python script from PHP using the following command: exec('/usr/bin/python2.7 /srv/http/assets/py/switch.py arg1 arg2'); However, PHP simply doesn't produce any output. Error reporting is set to E_ALL and display_errors is on. Here's what I've tried: I used python2 , /usr/bin/python2 and python2.7 instead of /usr/bin/python2.7 I also used a relative path instead of an absolute path which didn't change anything either. I tried using the commands exec , shell_exec , system .

Running a Python script from PHP

守給你的承諾、 提交于 2021-02-11 16:55:44
问题 I'm trying to run a Python script from PHP using the following command: exec('/usr/bin/python2.7 /srv/http/assets/py/switch.py arg1 arg2'); However, PHP simply doesn't produce any output. Error reporting is set to E_ALL and display_errors is on. Here's what I've tried: I used python2 , /usr/bin/python2 and python2.7 instead of /usr/bin/python2.7 I also used a relative path instead of an absolute path which didn't change anything either. I tried using the commands exec , shell_exec , system .

How to make wc accept a pipe file to take input from instead of stdin?

≯℡__Kan透↙ 提交于 2021-02-10 18:33:15
问题 This is a homework problem. The task is to replicate the command: ls | wc -l in a C program using execlp , fork , and pipes. My Approach I think the problem can be solved this way: Create a pipe file: pipe.txt Create a child process using fork() Map the stdout of the child process to pipe.txt Execute ls using execlp This puts the output of ls into pipe.txt Inside of parent process Map the stdin of the parent process to pipe.txt Execute wc -l using execlp without giving any further arguments

I was getting output of exec.Command output in the following manner. from that output I want to get data which I needed

老子叫甜甜 提交于 2021-02-10 15:44:00
问题 Here from output I want only json data with requestStatus Failed part only. remaining json data should be override each update/can be deleted. could you pls suggest me how can I get data which is only required. source Code: my source code looks like this. cmd := exec.Command(command, args...) cmd.Dir = dir var stdBuffer bytes.Buffer mw := io.MultiWriter(os.Stdout, &stdBuffer) cmd.Stdout = mw cmd.Stderr = mw // Execute the command if err := cmd.Run(); err != nil { log.Panic(err) } log.Println

Golang get command tty output

青春壹個敷衍的年華 提交于 2021-02-08 05:23:23
问题 I'm using go's exec Run command to get command output, which works great when the command 'Stdout' field is set to os.Stdout , and the error is sent to os.Stderr . I want to display the output and the error output to the console, but I also want my program to see what the output was. I then made my own Writer type that did just that, wrote both to a buffer and printed to the terminal. Here's the problem—some applications change their output to something much less readable by humans when it