stdin

python open() - access denied

浪子不回头ぞ 提交于 2021-02-20 19:36:55
问题 This is my first post on stackoverflow, so if somethings wrong I'm eager to learn! I'm programming a plugin for Cinema 4d with python. Everything works on Mac, but I'm having problems on Windows with what I'm about to explain. The plugin needs a path to a server, in case of rendering on a renderserver. I want the user to enter the path once, and to then store it in a .txt file. for c4d, plugins are being installed, by draging-and-droping the plugin into the plugin folder at for example: C:

python open() - access denied

我怕爱的太早我们不能终老 提交于 2021-02-20 19:36:13
问题 This is my first post on stackoverflow, so if somethings wrong I'm eager to learn! I'm programming a plugin for Cinema 4d with python. Everything works on Mac, but I'm having problems on Windows with what I'm about to explain. The plugin needs a path to a server, in case of rendering on a renderserver. I want the user to enter the path once, and to then store it in a .txt file. for c4d, plugins are being installed, by draging-and-droping the plugin into the plugin folder at for example: C:

How to intercept transparently stdin/out/err

南笙酒味 提交于 2021-02-19 09:27:07
问题 I would like to catch all the inputs and output of a commandline program (namely, GDB, but currently changed to ls or cat for simplicity) and redirect it into a file, for later analysis. I couldn't get anything close to working, but I can't understand what's wrong. Here is my last attempt: #!/usr/bin/env python2 import subprocess import sys import select import os def get_pipe(): fd_r, fd_w = os.pipe() return os.fdopen(fd_r, "r"), os.fdopen(fd_w, "w") out_r, out_w = get_pipe() err_r, err_w =

How to intercept transparently stdin/out/err

对着背影说爱祢 提交于 2021-02-19 09:25:43
问题 I would like to catch all the inputs and output of a commandline program (namely, GDB, but currently changed to ls or cat for simplicity) and redirect it into a file, for later analysis. I couldn't get anything close to working, but I can't understand what's wrong. Here is my last attempt: #!/usr/bin/env python2 import subprocess import sys import select import os def get_pipe(): fd_r, fd_w = os.pipe() return os.fdopen(fd_r, "r"), os.fdopen(fd_w, "w") out_r, out_w = get_pipe() err_r, err_w =

Python cgi and stdin

回眸只為那壹抹淺笑 提交于 2021-02-10 23:17:04
问题 I'm using pycurl to upload a file via put and python cgi script to receive the file on the server side. Essentially, the code on the server side is: while True: next = sys.stdin.read(4096) if not next: break #.... write the buffer This seems to work with text, but not binary files (I'm on windows). With binary files, the loop doing stdin.read breaks after receiving anything around 10kb to 100kb. Any ideas? 回答1: You need to run Python in binary mode. Change your CGI script from: #!C:/Python25

python input() takes old stdin before input() is called

夙愿已清 提交于 2021-02-10 17:35:42
问题 Python3's input() seems to take old std input between two calls to input() . Is there a way to ignore the old input, and take new input only (after input() gets called)? import time a = input('type something') # type "1" print('\ngot: %s' % a) time.sleep(5) # type "2" before timer expires b = input('type something more') print('\ngot: %s' % b) output: $ python3 input_test.py type something got: 1 type something more got: 2 回答1: You can flush the input buffer prior to the second input() , like

Prepend timestamp to each line received from stdin

旧城冷巷雨未停 提交于 2021-02-10 15:40:22
问题 Hi there I'm trying to create logs using bash but the time I'm getting is wrong. I'm running this in background. # log code here before executing curl script log "Yay I was started" curl https://example.com/process | sed "s/^/$(date -u) /" >> /path/to/logs.log & The time set after processing curl is the time it was executed not the time after I got the response. I need to get the time after the response. Here's the sample output (Wrong response) Fri Aug 21 01:43:12 UTC 2020 Yay I was started

Prepend timestamp to each line received from stdin

给你一囗甜甜゛ 提交于 2021-02-10 15:39:43
问题 Hi there I'm trying to create logs using bash but the time I'm getting is wrong. I'm running this in background. # log code here before executing curl script log "Yay I was started" curl https://example.com/process | sed "s/^/$(date -u) /" >> /path/to/logs.log & The time set after processing curl is the time it was executed not the time after I got the response. I need to get the time after the response. Here's the sample output (Wrong response) Fri Aug 21 01:43:12 UTC 2020 Yay I was started

How to flush stdin without requiring user input? [duplicate]

岁酱吖の 提交于 2021-02-08 19:41:43
问题 This question already has answers here : How to clear input buffer in C? (12 answers) How to clear stdin before getting new input? (4 answers) Using fflush(stdin) (6 answers) Closed 2 years ago . I'm trying to simulate a command line shell. The user inputs a shell command they want to input, e.g. /bin/pwd and the code is meant to execute it. The buffer is set to read a fixed number of chars (let's say 20 for example). In the case that the user inputs more than 20 chars, the excess characters

How to flush stdin without requiring user input? [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-08 19:41:38
问题 This question already has answers here : How to clear input buffer in C? (12 answers) How to clear stdin before getting new input? (4 answers) Using fflush(stdin) (6 answers) Closed 2 years ago . I'm trying to simulate a command line shell. The user inputs a shell command they want to input, e.g. /bin/pwd and the code is meant to execute it. The buffer is set to read a fixed number of chars (let's say 20 for example). In the case that the user inputs more than 20 chars, the excess characters