How do I run a non system command in ruby? - ruby

We have an automation script which we run in Windows command prompt.
We use it like 'Automate task 1'
Now I am trying to run it using ruby. I followed this SO post.
But since this is not a system command it doesn't get executed.
system('Automate task 1')
How do I excute such commands?
Note: We don't have access to type or source of that command nor knows where is the command stored. We just execute it in cmd.

Related

docker RUN on windows what happens?

I struggle to understand what happens when docker build runs on windows.
Especially the RUN instruction.
I have seen scripts where after RUN instruction follows powershell code. But in my case I have to use cmd code. Is there a switch? How can I make the RUN run powershell?
RUN ["powershell", ... causes:
'["powershell"' is not recognized as an internal or external command,
Is there a switch? Configuration? Flag?
Unfortunatelly the code words are kind of difficult to google due to "run" "command" and similar being kind of really general.
EDIT: (code in question)
ARG MINGW32_SCRIPT=install_mingw32.ps1
ARG MINGW32_INSTALLER=mingw-get-0.6.2-mingw32-beta-20131004-1-bin.zip
ADD ${MINGW32_SCRIPT} ${BASE_PATH}\\${MINGW32_SCRIPT}
COPY ${MINGW32_INSTALLER} ${BASE_PATH}\\${MINGW32_INSTALLER}
RUN powershell -command "%BASE_PATH%\%MINGW32_SCRIPT%"
This is what I have now, this works. But the return value of the script is ignored. (As powershell returns sucessfully.)
I want the last line to be something like:
RUN ${BASE_PATH}\\${MINGW32_INSTALLER}
I want the build to fail when the script fails. But this fails. (As for some reason after RUN I have to post CMD code. It calls cmd, that calls powershell.
If it matters, the win is server 2016.
Thanks for help
operable program or batch file.

How to send commands to running CMD instance

On Windows 10 I have a special developer command prompt (DevEnv). Every time another program (Matlab) creates a file output, I have to run a command in this command prompt to start another process:
myDevEnv.bat (sets environment variables, starts server instances, ...)
Matlab script creates myFile.foo
In DevEnv: doSomethingWithFiles.bat myFile.foo
I would like Matlab to call the third command from within the DevEnv. So my idea was to write the commands to a file, that is permanently read and executed in the DevEnv. Is this possible in a Windows command prompt?

execute powershell commands with Lua

I have a program that I work with, that has an onboard lua compiler to allow for custom written actions.
Since the tool itself is very limited, especially if it goes for complex reactions over networks, I want to use Powershell over lua.
Methods like os.execute() or io.popen() use the standard command line from windows and not Powershell.
Is there a way to use Powershell with lua?
I tried to write a command line script with the Powershell editor and run this script with os.execute, but it opens it as a textfile, it would be better to write the commands directly in lua but if there is no other way, executing a Powershell script directly would also be fine. (In Windows itself you can execute the script with right mouse "click/Execute with Powershell")
-- You can generate PowerShell script at run-time
local script = [[
Write-Host "Hello, World!"
]]
-- Now create powershell process and feed your script to its stdin
local pipe = io.popen("powershell -command -", "w")
pipe:write(script)
pipe:close()
Your description of the problem makes it sound like you're using a command such as os.execute("powershellscript.ps1"), and that call invokes cmd.exe with your string as the proposed command line. Normally, Windows will open a .PS1 file for editing; this was a deliberate decision for safety. Instead, try altering the os.execute() command to explicitly call PS: os.execute("powershell.exe -file powershellscript.ps1"). If you need to pass parameters to your script, enclose them in {}. See https://msdn.microsoft.com/en-us/powershell/scripting/core-powershell/console/powershell.exe-command-line-help for more info on invoking PowerShell from the command line.

Ruby: How to open .exe file(that open CMD) and run command init

I am trying using ruby script to a task.
I have an .exe file that i want to run.
when opening this file it open in CMD and i can pass commands to it.
That file located in C:\temp\test.exe
I need to go to the directory and then open the file and then insert to it command like:
"getobject" task = "aa"
this program will give me the result to the CMD.
i will need to copy the result to text but i think i can handle it late.
I tried to search it online cant found anything.
Thanks
If you want to open an executable, usually you can use the `command` syntax in Ruby. So call:
`C:\temp\test.exe`
That should run the executable from the Ruby script. Then you can interact with that executable as if you ran it from a CMD instead of a Ruby file.
In order to run and capture the output of a command you'll need to use a system command. There are many system commands that you can use, but my preference is Open3:
require 'open3'
output, status = Open3.capture2("C:\temp\test.exe")
In the event that you want to pass command line arguments to capture2 you'll want to write that like this: Open3.capture2("C:\temp\test.exe", "arg1", "arg2"). That is the safest way to pass arguments.
I think what you are looking for is input/ output redirection
check redirection
Not tested
system 'C:\temp\test.exe < "\"getobject\" task = \"aa\""'

How to extract information from a command prompt using shell script?

I need a shell script using which I can fetch data from command prompt. I need to fetch data from the command prompt of a router. When I write commands in a shell script it goes the prompt but not executing the next command. So running the script just stuck in the prompt. Bellow is my script file
#!/bin/sh
ccli
rsc
where ccli is the command to enter the prompt and rsc is the command to fetch some infomation.
So please suggest some method.
If ccli reads commands from stdin (which I don't know), you might get further with
printf 'rsc\n' | ccli
For more complicated tasks I suggest you look into expect which was invented for the sole reason of driving interactive programs in a scripted way.

Resources