I'm making a Vim plugin that uses Open3.popen3 to run a shell command, and I need the result and exit code. It works fine on Linux, but freezes on Windows. I've checked on pry under Windows and whenever I run Open3.popen3 or Process.spawn the shell just freezes. I've tried to install the win32-open3-19 gem(and load it with require 'win32/open3) - but it still freezes.
Is there any other method or gem I can use? I prefer something as close as possible to Open3(so my Linux and Windows versions can share as much code as possible).
I'm running Ruby 1.9.3 installed via RubyInstaller on Windows 7 64bit.
MORE DETAILS:
This is the exact code I want to run: https://github.com/someboddy/vim-erroneous/blob/master/autoload/erroneous.rb#L43
It works on Linux but freezes on Windows.
On my Windows, I open pry and then write:
require 'win32/open3'
inp,out,err,wait_thr=Open3.popen3('cmd')
And my shell freezes. When I try it on Linux(using 'bash' instead of 'cmd') it works just fine. I've also tried 'dir'(which shouldn't wait for user input) and it also froze.
Related
I have a ruby script that runs many external executables (.exe). I run these executables in two different ways.
sytem(program)
IO.popen(program), in this case I need the PID since later on I monitor this process.
My UI is designed with FX ruby. When I run the program through my cmd console (ruby MyScript.rb) everything works fine and I don't see any pop-up.
Then, I generate an exe with the OCRA gem by using the following syntax:
ocra MyScript.rb --gem-all --windows
The exe is generated correctly; however, when I run any external program, through system or popen, there is a cmd window popping up during the time the exe is running.
Is there a way to hide these cmd windows?
I am running compiled c code on the Ubuntu subsystem for Windows. I would like to automate this process with a Python script that can open the terminal, send and read commands as well as closing the window.
I am trying this on Python 3.6 in Windows 10. I thought it was going to be the same as interfacing Python with the CMD but all the things I try are not yielding results. I want to know if anyone has tried to automate processes with the Ubuntu subsystem for Windows and how can that be achieved.
First, I had to find the .exe that launches the Ubuntu app, since it's downloaded from the microsoft store.
Using OS simply gives me the following result without opening the terminal.
import os
os.system(r"C:\Program Files\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_1804.2019.521.0_x64__79rhkp1fndgsc\Ubuntu.exe")
1
Also using subprocess will open the terminal. But parting from there, how can I give it commands and read the outputs?
import subprocess
subprocess.Popen([r"C:\Program Files\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_1804.2019.521.0_x64__79rhkp1fndgsc\Ubuntu.exe"])
I think there's a few things worth mentioning here.
Firstly, I don't think you need to use Python at all. If you want to schedule your compiled C code to run at a particular time (or linked to some other condition etc.), you can do all of this within WSL. I would suggest using cron which already comes with Ubuntu. It's a scheduling daemon that can execute tasks at specified intervals.
Secondly, if you want or need to use Python to achieve this (for whatever reason), I suggest you install a second version of Python within WSL. This will allow you to easily run whatever shell commands you want e.g. to execute your compiled C code. You don't need to worry about opening an Ubuntu window and then closing it etc. Personally I would actually go further and say that you should ditch your Windows 10 Python and just go with the WSL Python - it makes a lot of things much easier, especially if you're already familiar with Linux or are using WSL a lot for other tasks anyway.
Lastly, if you still really need to automate this from Windows 10, I suggest you use the Windows Task Scheduler to schedule a .bat file which opens bash (WSL) and executes a command as per the following link:
How to run program on ( ubuntu bash windows 10 ) from windows task scheduler
(or if you don't need to schedule it, you can instead just execute the command from Python)
Hope that helps!
Ansicon does not seem to want to work with Windows 8.
1 - I install it correctly : ansicon -i under the x64 directory (since I have Win 8 on a 64-bit machine/install),
2 - I launch a new command window, run rspec to run unit tests in ruby
Result - the ANSI characters are still displaying the raw unconverted data.
Any help would be appreciated; thanks.
Sounds like ansicon might not have installed correctly. I've got ansicon working well on Windows 8 64-bit with Ruby 1.9.3p392.
http://imgur.com/n28vomG
Try running ansicon -i from an elevated Command Prompt and see if that makes any difference. If you don't have administrator permissions, run ansicon -p to hook into the parent process for the current session and then see if rspec returns colored output then.
If you still can't get it to work, maybe try reinstalling the latest version of ansicon. I installed the 64-bit files (ANSI32.dll, ANSI64.dll, ansicon.exe, ANSI-LLW.exe) in my Ruby's bin directory so I know it's in my PATH.
I did a cheap trick and just made a shorcut directly on my desktop in order to use it.
adding it to the path crashed ruby.
Does anyone know how to run/compile Ruby programs on Windows 7? For example you can compile Java in Eclipse, but I can't seem to find one for Ruby.
http://rubyinstaller.org/ - "The easy way to install Ruby on Windows".
Will give you the language and execution environment - everything you should need to get started.
Ruby isn't compiled, but rather interpreted. You need to install Ruby using the above link given by #ilollar.
Then, if you have the source code of a program in the file some_ruby.rb, you will execute this in cmd:
ruby some_options.rb
This is the general form of a ruby command:
ruby [ruby options] [program name] [program options]
Here is a free online book that will answer most of the question you have about Ruby if you are just starting out: http://ruby.learncodethehardway.org/book/
It's called "Learn Ruby the Hard Way", but don't let the name throw you off - the book is actually pretty easy to follow and doesn't assume you know anything about programming.
It will get you started writing Ruby and running programs for the first time.
Like ilollar said, the Ruby Installer is the best way to put Ruby on your Windows computer.
I'm currently running Ruby on Windows 7 writing Rails applications. You can do a lot on Windows with Ruby, however, you can't do everything. There are bundles of files that you can download that will help you write your Ruby programs - they are called Gems. Some gems will not run on Windows - The Ruby Racer and some versions of EventMachine are two that immediately come to mind.
This can be frustrating, but if it ever happens you can install a version of Linux in a virtual machine on your Windows computer so that you can use these gems without having to get a new machine.
You can also install Linux to run alongside Windows without having to reformat or mess with the partitions on your hard drive. There is a program called 'Wubi' that will install Ubuntu (a version of Linux) to run inside your Windows machine. It will actually let you pick Windows or Linux when you start your machine.
But all this is stuff to think about later on. You can certainly develop Ruby on Windows for now.
Also, in case you want to run just Ruby interactively, find the location where it is installed and browse to the bin subdirectory. For me this was \RailsInstaller\Ruby1.9.3\bin. In this directory there should be a file irb.bat. Double-click on it and you'll get a Ruby console session.
You can create window executables with ocra. That way you can create the app and push the app to another pc that does not have Ruby installed on it.
Is there a ruby visual debugger that i can run from the linux terminal?
And if so, how do i run it?
There are several graphical debuggers available for Ruby, e.g Mr. Guid, rudebug or the RubyMine IDE, the latter of which does not seem to quite fit your use case. ruby -r debug [script] runs on the command line but is also quite usable.