Unable to get -r parameter working - console2

I've tried in every way imaginable to execute a shell command from command line but it simply doesn't work. What am I doing wrong?
C:\Console2\Console.exe -r runstuff.bat
C:\Console2\Console.exe -d C:\Console2 -r runstuff.bat
C:\Console2\Console.exe -r dir
Neither works. (Win7 x64)

I am playing with that now.
Did you try:
console2 -r "/K runstuff.bat"
The /K is needed to keep the command open after running the script.
The problem I'm having with the "-r" option is that I'm having to type exit twice to leave the window.
If you add the command to shell command (settings... -> Tabs -> Shell) field you will not have to type exit twice:
%comspec% /K runstuff.bat
I don't think the "%comspec%" is necessary (could use "cmd" instead), but I got it from an example somewhere on the web years ago. Console2's included help file shows using "cmd".

Related

How to run an awk command?

I am trying to learn how to calculate polygenic risk scores and I am following a step-by-step tutorial (this one: https://choishingwan.github.io/PRS-Tutorial/plink/). However, I have been stuck trying to figure out how to run this command:
awk 'NR!=1{print $3}' EUR.clumped > EUR.valid.snp
Obviously, this is not something I can make run in R, but apparently by using system(), people said it should work. But it doesn't. I then tried to run this command in my own Windows command prompt but it doesn't recognize awk as an intern command.
I then tried to maybe update my command prompt with wsl --install (because that's the only conclusion I could come up to) but apparently my administrator account needs permission to do so.
It would be useful if you could mention a couple of things:
Does R give you an error?
I assume you are trying to run it on a linux system with awk installed?
To check if awk is installed, try running this in your linux terminal:
which awk
To run your awk command from within R, you should escape the ' characters with a \ in your awk command, and put the entire command within quotes:
system('awk \'NR!=1{print $3}\' EUR.clumped > EUR.valid.snp')

Cursor keys dont work in vim when running zsh on wsl through cmder or conemu

I'm running ubuntu 1804 on windows using the WSL. Everything is set up fine and works correctly. I've also installed ZSH and oh-my-zsh, again this is all good and everything looks like its working fine. Everything except the arrow keys whilst using vim or man pages or some other command line tools.
The up and down keys work on the command line when scrolling through history and also for select commands like nano. Also if I boot into bash rather than zsh the arrow keys do work in vim and man pages, in fact they work everywhere.
If i boot into bash, then switch to zsh on the command line manually the arrow keys then work everywhere.
So my cmder config for zsh
c:/_distros/ubuntu1804/ubuntu1804.exe -c zsh -cur_console:pm
and for bash
set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -cur_console:pm:/mnt
The one for bash uses the conemu-cyg-64.exe program that comes from conemu which is a symbiont of POSIX enabled pty and WinAPI full-featured terminal.
Apparently you can use this tool with zsh but i cant manage to make it work i get the error
{PID:10592} failed to run shell (2): No such file or directory
{PID:10592} shell: `/usr/bin/zsh` `-l` `-i`
{PID:10592} dir: `/cygdrive/c/Program Files/cmder`
ConEmuC: Root process was alive less than 10 sec, ExitCode=0.
Press Enter or Esc to close console...
and this is the task in cmder
set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe /usr/bin/zsh -l -i -cur_console:pm:/mnt
So I think that if i can boot into zsh using conemu-cyg-64 that the cursor keys will probably work in commands like vim and the man pages. Any help or advice getting that working would be brilliant.
EDIT:
On my ubuntu install zsh is installed at /usr/bin/zsh, but there is no file or folder /cygdrive/c/Program Files/cmder
Many thanks to #Maximus for pointing me in the right direction. The answer was right under my nose at the bash on windows page of conemu. A small change to the command i was using before. the zsh needs to go on the end rather than before the --wsl.
The correct task to ensure that cursor keys work on all apps in the terminal is:
set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -cur_console:pnm:/mnt -t zsh -l

Way to get jupyter server root directory

Consider following:
$ cd /home/mydir
$ jupyter notebook --port=8888
In plain English, I am running jupyter server from /home/mydir directory.
Is there a simple way to get this directory from within a notebook regardless if it's a R notebook or a Python notebook or whatever? Maybe there is some magic command or variable?
NOTE: getwd() is not an answer as it returns directory of a current notebook but not the jupyter server root.
I have a similar problem and found your post, although I don't see a viable solution yet. Eventually I did found a solution, although it works only because I only care about Linux and I only care about Python. The solution is this magic line:
J_ROOT = os.readlink('/proc/%s/cwd' % os.environ['JPY_PARENT_PID'])
(I put it in a module in my PYTHONPATH so that I can easily use it in any Python notebook.) See if it is good for you.
Remember that your iPtyhon is just a Python module, so you can execute any valid Python code in a cell. So, if you started your notebook and haven't executed any directory changes in your code, you should be able to retrieve your cwd with the following in a cell:
import os
os.getcwd()
But furthermore, you can execute shell commands in cells, so you can retrieve other information in the cell. For example:
!which jupyter
should give you the path to your jupyter executable.
Which then leads you to running something like:
!jupyter --paths
which should give you something similar to:
​
config:
/Users/yourdir/.jupyter
/usr/local/etc/jupyter
/etc/jupyter
data:
/Users/yourdir/Library/Jupyter
/usr/local/share/jupyter
/usr/share/jupyter
runtime:
/Users/yourdir/Library/Jupyter/runtime
Frankly I'm surprised that all this time later there is still no built-in way to do this. I have used Isaac To's solution on Linux but recently had to make a jupyter notebook portable to Windows as well. Simply using os.getcwd() is fragile because a cell using it to set your JUPYTER_ROOT_DIRECTORY can potentially be called again, after you have changed your working directory.
Here is what I came up with:
try:
JUPYTER_ROOT_DIRECTORY
except NameError:
JUPYTER_ROOT_DIRECTORY = os.getcwd()
I put it in one of the first couple cells with the initial import statements. If the cell gets called again, it will not re-set the variable value because the variable exists and does not throw an exception.
It should be noted that unlike Isaac To's solution it sets the value to the directory the current .ipynb was run from, which is not necessarily the same directory as the top-level dir the user can access in the left hand file pane.
My suggestion is to use an intuitive approach.
Create a new folder within the Jupyter environment with a very unique name, for example, T246813579.
You can now locate the Jupyter working path by searching in your file explorer. For example, you can use the Windows Explorer in order to locate your new folder.
The expected result should look something like this:
C:\Users\my_user_name\JupyterHome\T246813579
The answer from #Isaac works well for Linux, but not all systems have /proc. For a solution that works on macOS and Linux, we can use shell commands, taking advantage of the ! shell assignment syntax in Jupyter:
import os
JPY_ROOT = ! lsof -a -p {os.environ['JPY_PARENT_PID']} -d cwd -F n | tail -1 | cut -c 2-
JPY_ROOT = JPY_ROOT[0]
print(JPY_ROOT) # prints Jupyter's dir
Explanation:
Get the process ID (pid) of the current jupyter instance with os.environ['JPY_PARENT_PID']
Call lsof to list the process's open files, keeping only the current working dir (cwd)
Parse the output of lsof using tail and cut to keep just the directory name we want
The ! command returns a list, here having only one element
Alternate Version
To save the os import, we could also use shell commands to get the PID. We could also do the subsequent string wrangling in python, rather than calling tail and cut from the shell, as:
JPY_ROOT = ! lsof -a -p $(printenv | grep JPY_PARENT_PID | cut -d '=' -f 2) -d cwd -F n
JPY_ROOT = JPY_ROOT[2][1:]

SSHLibrary - A shell script with arguments exits with code 127 and error 'java: command not found'

Using Robotframework automation with ssh library, i am trying to execute a shell script with one argument (-a), on a remote UNIX box
The test steps are as follows:
Login to the UNIX box
Go to the directory where the shell script with argument (-a) is present
Execute the shell script
Please note:
Since 'SSHLibrary' keywords like 'Execute command' or 'Write' and 'Read' work in a single shell, i am passing multiple commands separated by a semicolon
In the series of commands, i also tried turning ON the shell using command shopt login_shell but this too did not work. Also note that the command shopt login_shell is not turning ON the shell when executed with 'Execute command' keyword. It works fine with 'Write' keyword
The following command to check if JAVA is loaded in the automation shell, returns a correct output (path to JAVA).
Write $JAVA_HOME
${Op_java}= Read
Problem:
Following robotframework test step after logging in to the UNIX box fails with exit code 127 and error 'java: command not found'
Method 1 that I tried:
Write shopt login_shell
${Op_Shopt}= Read
${Op_rc} ${Op_err}= Execute Command cd /home/xyz/abc; ./shell_script.sh -a return_stderr=True
Here the login_shell is turned ON but somewhere within the shell script the Execute Command keyword exits with code 127 and error 'java: command not found'
Method 2 that I tried:
Write shopt login_shell; cd /home/xyz/abc; ./shell_script.sh -a
${Op_shell}= Read
Here the login_shell is NOT turned ON and even here too the Execute Command keyword exits with code 127 and error 'java: command not found'.
As mentioned below, i also tried the same approach with the keyword 'Start Command', but still the same issue.
Start Command shopt login_shell; cd /home/xyz/abc; ./shell_script.sh -a
${Op_rc} ${Op_err}= Read Command Output return_stderr=True
Can someone please help me to resolve this problem?

Use cmd commands in QT

Hi i was checking and anyone can use commands very similar in cmd like dir mkdir etc.
But for example when i try to use command (cd ..) i couldn't
QProcess consola;
consola.start("cmd.exe /C " + comando);
consola.waitForFinished();
consola.waitForReadyRead();
This is the question how i can use more commands in cmd for qt for example.
At least from the command line:
cmd /C "cd \"
works as did directories other than root. (Note the parenthesis around the command since it contains embedded spaces.) However, this example isn't very useful because this executes the command shell, changes the directory in that command shell, and then the command shell disappears, and your current directory is back to where you started.
I recommend looking into the QDir class, which has methods such as "current ()" and "setCurrent ()" for getting and setting the current directory. There are equivalents for mkdir and many others. Also, using QDir is much more cross-platform friendly, where using the "cmd" shell is Windows-specific.
You don't say what you're trying to accomplish, so beyond that suggestion, it's impossible to know how to best help you.
Your process's current directory can be and mostly is different than current directory of your is running. Please read chdir manpage for that.
That command is mostly working but changing the current directory of your process.

Resources