Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
I am trying to save everything my python app printed in the cmd, every solution I found was to get the response of a command line using Popen from Subprocess; what I want is to get everything. Is there a built-in function for this purpose? or should I do it manually, which I don't prefer?
What you want to do, is log the output of stdout, see this answer:
Making Python loggers output all messages to stdout in addition to log file
Why don't you use this from terminal
python main.py > output.log
you can try the script command in your shell. It saves everything printed out to your shell from the moment you call it. End the command with exit. you can call it from your python script, hope it helps.
script manual page
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a code that needs to get an input from the console.
I am doing it to be able to debbug a code with input from console becuase pycharm does not allow me to pause during execution.
I want to be able to provided the input i want beforehand , i.e to provide it automatically through the code as if it was provided from the console.
Is this possible?
If you use input(), PyCharm will pause execution to wait for input just as if you run in the console.
Alternatively, you can use sys.argv to take command line parameters. You can add these parameters to the run configuration in pycharm.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have been making a program that opens a different file (extension is .ebj) and shows you the 3d object saved inside it with pygame, so kind of like a simple programming language. Currently i have found how to choose what file you want to open using sys.argv but is there a way to make it so you can run the .ebj file and it will automatically run the python code with the file you ran as the parameter
You description is a bit difficult to decipher. I think you need your python script to run a file? That's what I'm assuming after seeing your reference to sys.argv as holding the file you'd like to run.
If I have that correct, then how you go about running that file is going to be dependent on which OS you're operating on. I'll assume windows, but forgive me if I'm off on that.
Here's how I have my windows machine run a software package using the windows default application based on the file ext.
import subprocess
filename = GET_YOUR_FILENAME_HERE
subprocess.call("start " + filename, shell=True)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
It will great help if you can explain with code example or any useful resource.
you can use the in-built pdb library.
import pdb
a = 10
pdb.set_trace()
print(a)
So what it would basically do is, stop the program after line 2 is executed. and from there you would have command line access to the code with is execute above the set_trace() is added.
You can read more about it here.
The breakpoint() method is part of the python language now. See: https://www.python.org/dev/peps/pep-0553/
If you are using an earlier version of python then you can have the same functionality by importing pdb by import pdb at the top of you file and pdb.set_trace() where you want to be able to inspect variables.
When you are dropped into the pdb shell you type h to see what commands are available.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to run a background script with Fabric using Bash's '&' operator. Is there a reason the following doesn't work? I executed this command on the server itself and it runs fine.
#task
def run_script():
sudo('sh /home/ubuntu/wlmngcntl.sh start &', user='myuser')
I don't want to use something heavy like Celery to do this simple thing. I don't need to capture the output at all, all I want is for the task to execute this and return after.
This isn't a Fabric thing, but a Linux thing. When you close a session, the processes connected to that session are terminated.
This question has a lot of info... https://askubuntu.com/questions/8653/how-to-keep-processes-running-after-ending-ssh-session
You could use the following (from that answer)
sudo('nohup sh /home/ubuntu/wlmngcntl.sh start &', user='myuser')
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
So I ran some python script on some files by
ls * | xargs python myscript.py
After the process finished normally, I looked at the process by
ps aux
I find that the process is still in the list. I have to manually kill it. Why is this? Here is my python script.
import sys
filex = open(argv[1])
for line in filex:
do sth here.
Unless you have skipped it in your post are you not calling close() on the file afterwards?
Try calling filex.close() at the end or alternatively use 'with':
with open(argv[1]) as filex:
for line in filex:
#do the things