Probably a very simple question. I just thought, after someone suggested it here, of trying (and installing) Python 3.6 on a Mac - I've been happily using 2.7 since now. I've never used the IDLE before having done everything via the command line + ATOM to write the program.
I see that 'normally' you should be able to write your program in the shell and then run it in the RUN window. However, I don't see a RUN mode in window, just the possibility of using, which you are anyhow, the shell window. I hope that makes sense!
Is this normal, or have I missed something?
p.s. I'm using OS X 10.8, if that's of any importance.
I am not exactly sure what you are asking, and whether it has anything to do with OSX, but I can explain IDLE. IDLE has two types of main window: a single Shell and multiple Editor windows.
Shell simulates python running in the interactive REPL mode that you get when you enter 'python' (or 'python3') in a console or terminal window. (The latter depends on the OS.) You enter statements at the >>> prompt. A single-line statement is run when you hit Enter (or Return). A multi-line statement is run when you hit Enter twice. This is the same as in interactive Python.
Editor windows let you enter a multi-statement program. You run the programs by selecting Run and Run module from the menu or by hitting the shortcut key, which by default is F5 (at least on Windows and Linux). This runs the program much the same as if you enter python -i myprogram.py in a console. Program output and input goes to and is received from the Shell window. When the program ends, Python enters interactive mode and prints an interactive prompt (>>>). One can then interact with the objects created by the program.
You are correct that Run does not appear on the menu bar of the Shell. It is not needed as one runs a statement with the Enter key.
Related
I am writing a service program which is expected to run in background. On Windows it will open a console window when run. I want it to go to background directly without that console window, so I used the -ldconf "-H=windowsgui" option, which worked as expected.
However, there is a catch. The program has a command line option -help, which output command line usage in the console. If I use -H=windowsgui, the help text is NOT printed even I start it in cmd.exe prompt.
It seems that the windowsgui option is not what I want. Is there anyway that the -help still works at commant line, and the console window will not persist if the program runs normally. I do not care if there is a console window pops up, provided that it disappears shortly without user intervention. i.e. I want a way on windows which is similar to the & operator on Linux.
P.S. if provided solution uses any other tools, I want that tool to be a Windows component, not any 3rd-party program. Thanks.
I am using Ruby on a mac to open a dozen URLs one at a time with Nokogiri etc.
For each URL I need to let my ruby program know
whether to keep the URL window for further inspection or close it.
But I cannot see the terminal window and its prompt, it is hidden behind
the last URL window.
I have to click on the terminal window in order to bring it to the front, in order to enter my decision on the keyboard.
puts "close webpage?"
if gets =~ /^y/i then 1 ; else; 0; end;
I would like the terminal window to come to the front before it prompts
me for an answer.
I think the question is two fold
Is there a terminal command that tells a terminal window to become
the active one (the one in the front) that would work with mac iTerm.
The Apple script "bringiTermtofront" works in the applescript editor.
tell application "iTerm" to activate
Is there a way to execute a terminal command from ruby.
the ruby code
system "osascript bringiTermtofront.scpt"
brings the iTerm to the front.
For Question 1, one approach would be to write an Applescript to handle the switch, and then use the Terminal command osascript to run it from your Ruby code. You could also check if rb-appscript is still usable (it's no longer supported, but might work).
For Question 2, you have a few choices. Using backticks around the command will let you capture the output of a brief command, if you want to store the result of the command in a variable. (E.g. use grep or something similar).
The system method in Kernel is probably your best choice, though, as it will execute shell commands as if at the terminal.
Per the edit showing what script you're using, you need to execute the script as Applescript, not as a terminal script. You don't even need a separate file as it's just one line. This would be :
command = %q[osascript -e "tell application \"iTerm\" to activate"]
system(command)
You could also put the Applescript in a file and execute it using just
system("osascript bringiTermtofront")
See "Running shell commands from Ruby" for a little more help on how to interact with these methods.
I need script which works in the background, waiting for a key to be pressed. I have a script which works when terminal is on. When I try to use & - it's not working correctly. The script works in background but keypress doesn't do anything. When I try use nohup then I have error of read - bad descriptor.
Can someone help me?
When the terminal is on (and is selected, in case of a terminal emulator running on x server), the input (key strokes, etc.) is directed to the terminal; hence, your program works.
Now, consider an example: let's say that you created a script that runs on the background, and it is activated by pressing the letter "a". If pressing "a" triggered your script (with terminal closed), then the user would never be able to (for example) type the letter "a" in a word document or a web search without triggering the script!
Therefore, what you are looking for is a key bind, or a keyboard shortcut, which would bind a key (combination) such as ctl+j+k to launch the script you want.
In Linux, that can be done somewhat easily, see this for Ubuntu or this for Lubuntu.
Important: if your script needs to be root to work, then you generally will have to evoke it via gksu or gksudo, otherwise it will not run
I'm trying to figure out why, when I have a large output in the GNU Octave version 4.0.3 running on MacOSX ElCapitan GUI - magic(500) for example - and the "-- less -- (f)orward, (b)ack, (q)uit" prompt comes on screen I have to switch to the terminal to actually execute the command. It's kind of annoying to have to click the terminal just to type "q" so I can continue working in octave-gui after displaying a large output. It would be nice if I didn't have to take up space on my desktop with an open terminal window. I've had the GUI run the command from the command window, but I guess the settings got messed up in some way? Any help on this would be awesome.
You can disable paging within octave using a number of methods listed here.
more off
page_screen_output(false)
page_output_immediately(True)
I started using vim for my programming projects (mostly Ruby) and mostly everything works just as I want but I have a problem with compiling.
Lets say I am working on a Ruby script and I want to run it. I type :ruby sometging.rb (mapped to some other key). Then vim opens a new cmd.exe window and runs 'ruby something.rb'. Then it waits for me to press ENTER to close the window and continue working on the script.
Is there a way to configure vim on windows so that it always runs the script I'm working on in a separete window (always the same one, if none exists => open one), and not ask me to confirm with enter?
Don't know about gvim, but in normal vim you could put something like
map R <ESC>:tabnew<CR><ESC>:;%!ruby filename.rb<CR>
in your ~/.vimrc which would execute a Ruby file in a newtab when pressing R in command mode.
I've not used Ruby, but for I've found Dr Chip's RunView plugin really useful for running other interpreted languages.
Once it's installed, you can enter:
:RunView! <interpreter>
(where <interpreter> is presumably 'ruby' in your case) and it will open a (vertically if you include the !) split window with the output from passing the contents of the current window to the interpreter. Each time it is run, a new result log is appended to the end of the file (with a date and time stamp separating them).
If you have any issues with it, I'd recommend you contact Dr Chip via the Vim mailing list: he's very helpful (in fact he wrote the original version of RunView in response to a request I made on the mailing list).
This isn't exactly perfect but I use this to launch Python scripts.
command -nargs=* PY3 !start cmd /K Python.exe "%:p" <args>
It starts up a window that stays alive and doesn't interfere with my VIM window. Unfortunately it doesn't load it into an existing window.