IRB analogue of python -i - ruby

I want to use IRB to run a script then give me an interactive prompt. I do this with python -i xy.py in Python, however irb xy.rb exits after execution.
> python --help
-i When a script is passed as first argument or the -c option is
used, enter interactive mode after executing the script or the
command

irb -r xy.rb
It simply requires the file mentioned before giving you a normal IRB prompt.

Related

How can I open shell and then execute a command inside it

What I want is to open default shell, then call another and execute a command there.
Was trying something like this:
c:/Windows/System32/bash.exe -c "zsh & zstyle"
or
cmd /k "c:/Windows/System32/bash.exe -c zsh" & zstyle - this open shell but doesn't run a commands
or
c:/Windows/System32/bash.exe -c "zsh -c 'zstyle'"
Currently I am using a cmder/conemu terminal for windows.
Unfortunately, passing a startup to command to zsh with -c and keeping it open for interactive use (with -i) doesn't work.
Disclaimer: The following solutions were tested from a regular Command Prompt (cmd.exe), not cmder/conemu, though I'd expect them to work there too.
To try them from PowerShell (v3+), insert --% as the first argument after (right after bash.exe).
Here's a workaround:
c:/Windows/System32/bash.exe -c "zsh -c 'zstyle' && exec zsh -i"
Note that command zstyle is executed in a different, transient zsh instance, so this approach won't work for commands whose purpose is to modify the environment of the interactive shell that stays open.
If that is a requirement, things get more complicated (this solution courtesy of this answer):
c:/Windows/System32/bash.exe -c "{ { echo 'zstyle'; echo 'exec 0<&3-';} | zsh -i; } 3<&0"
Note, however, that both commands being executed will be printed before their output, if any, is shown, preceded by the prompt - as if the commands had been typed interactively.

Nest execute commands in bash

I am trying to associate a hotkey with opening vim with recent history browsing, thus I have wrote the following line
gnome-terminal -x "vim -c ':browse old'"
However this gives
Error: Failed to execute child process "vim -c ':browse old'" (No such file or directory)
What am I doing wrong?
Good news! The -x option of gnome-terminal makes it very easy to start a new terminal and run a new program in it. Just do:
gnome-terminal -x vim -c ':browse old'
The meaning of -x is that all subsequent arguments are passed to the program that you run, so no quoting is needed.

Running a JMeter script with nohup

For the first time I'm just playing around with nohup on top of an Ubuntu server. I read few docs about nohup and got to know about the running commands with options such as nohup ./server.sh &.
What I want to know is that, how should I be running the JMeter script (in headless mode) using nohup? Following is the script I needed to run with nohup:
./jmeter.sh -n -t /home/chamith/WSO2MB/new/apache-jmeter-2.13/bin/GamesSubscriber.jmx
When I tried using the normal nohup operation within the script it always throws me an error saying -n command not found. How should I move on with this? Any help would be appreciated.
Although I cannot reproduce your issue you can try surrounding your command with quotation marks like:
nohup "./jmeter.sh -n -t /home/chamith/WSO2MB/new/apache-jmeter-2.13/bin/GamesSubscriber.jmx"
Also don't forget -l key to save the results into a file.
The full command which runs script totally in the background will look like:
nohup "./jmeter.sh -n -t /home/chamith/WSO2MB/new/apache-jmeter-2.13/bin/GamesSubscriber.jmx -l result.jtl" > /dev/null 2>&1 &
References:
nohup man page
nohup Execute Commands After You Exit From a Shell Prompt
How Do I Run JMeter in Non-GUI Mode?
Full list of JMeter command-line options

Vim run commands from bash script and exit without leaving shell in a bad state

If I do:
echo 'vim +BundleInstall +qall' | bash
it installs my bundles correctly, but leaves the shell in a bad state (ncurses options) because of the pipe.
Is there a way to prevent the shell from being in a bad state?
Same for the minimal test case: echo 'vim +qall' | bash
Similar to: Run vim command from commandline, but the question there was for an interactive shell, so vim +BundleInstall +qall was fine.
I want to do this to be able to automate Vim plugin installation as:
wget -O- http://a.com/bootstrap-scrit.sh | bash
in a bootstrap script that currently contains vim +BundleInstall +qall. This command can be changed if needed.
Vundle issue: https://github.com/gmarik/Vundle.vim/issues/59
You can source your script instead, like so:
. <(wget -O- http://a.com/bootstrap-scrit.sh)

Ruby system command is giving me an output

This ruby 'system' gives me an output; on irb:
system("sudo airodump-ng -w sidney wlan0")
Airodump-ng is from the Airocrack-ng package.
However, the ruby "system" should not give me a stdout.
The thing is, that a "sh" processus is being created, which doesn't have an output. But the "sh" processus got a child processus, which gives me a output that I don't want at all to be displayed on my terminal.
Second part of the question, how can I get the pid of that sub-processus, using threads and maybe a different way to call a shell command using ruby (and not displaying the output of that child processus) ?
If you don't care about the output, trash it:
system("sudo airodump-ng -w sidney wlan0 >/dev/null 2>&1")
I think the child process will inherit the parent's file descriptors.
Use
out = `sudo airodump-ng -w sidney wlan0`
instead, and output will not show on screen, but stored in out instead

Resources