disable console pop-up for shell script - bash

When I run a shell script in pycharm/powershell or command window, eg: ./abc.sh, then a popup window is open and then shows the status of the execution and closes before I could read it. Making it pointless. A better option would be to show the status right below when I input the command. Or redirect it to a text file. How to achieve it?

Run run the command in git bash and it stays in the window itself.

Related

Is there a way to launch Terminal with a prefilled statement?

I want to open a terminal window with a statement. Is there a process I can run that will do this?
For example, I want to run a script that 1. Opens Terminal and 2. has the following statement:
java -version
The user then can press the Enter key to run the statement
One way to do this is by wrapping the command in a .command file that contains a command to read something, such as:
#!/bin/bash
command="java -version"
echo $command
read input
exec $command
...then, make the script file executable by running chmod +x filename.command on the file that you put this in, and run it (e.g. from the Finder or by using open filename.command). This should launch the terminal, print the command, and wait for the user to press Enter before running it.
You will note that since this is a script, you can customize any of the steps above to do whatever you want, e.g. printing more stuff or running other commands.

Apple Script execute Unix executable

I'm currently pulling my hair out trying to make an apple script execute a shell script / Unix executable, so that I can drag it into the dock. I don't have much experience with AS, so this is propably an easy fix for many of you guys.
Here's the whole script:
to run
do shell script "/Users/MyUserName/Documents/cmus/2.7.1_1/bin/cmus"
end run
Cmus is a terminal music program that is a Unix executable.
When I try to run it, I get this error message:
error "Error opening terminal: unknown." number 1
What is the problem? Pls help...
I am guessing your program is curses based and needs a Terminal window, so try this:
to run
tell application "Terminal"
do script "/Users/MyUserName/Documents/cmus/2.7.1_1/bin/cmus"
end tell
end run
#TheUnderBrony don't use do shell script but use do script. do shell script is part of the standard addition.osax which open an shell in the background do script is part of the terminal which will execute the string in a terminal window.- dj bazzie wazzie
This solved my problem, thank you! But Only one slight problem is left: The terminal starts and opens the program, but it opens it in the background, aka, I need to click on the terminal icon to show the window. Do I need to activate the window? If so, how? But already thanks a bunch :)

Vim shell command messages output printed outside vim editor

Normally, whenever I enter shell command like !ls or rm file in vim, the message along with confirmation prompt will be printed below vim status line. My issue is, when I'm doing shell command, the message is printed out outside vim editor (like it was minimized) and then bring me back to the editor after I press enter button to confirm. What is causing this to happen?
UPDATE
This is what I mean:

Check if there are any running processes in the current tab of terminal

I have a script that opens up as many terminal tabs as are devices plugged in, then it runs tests on those devices. I would like to clean up all the terminal tabs after my tests are done. I run some things in the background, and I don't know when each process will be done.
How can I check if there are process running in the current tab of terminal?
I plan to do a Command W in AppleScript to kill each terminal command after each tab of terminal has no running processes.
Thanks!
If you use AppleScript, you can check the busy property:
tell application "Terminal"
repeat with t in tabs of windows
if busy of t is false then
do script "exit" in t
end if
end repeat
end tell
exit closes a tab if you set "Preferences > Settings > Shell > When the shell exits" to "Close the window".
One simple solution would be to take each command that you're running in a terminal and append "; exit" (Without the quotes) to it.
For example, if one of your commands was "ls", you would change it to "ls; exit".
Unfortunately, this doesn't work if you want to leave the terminal windows up to see results of what's being displayed. That can be solved by outputting the results of the first commands to some file, though.
Again using the example of ls, you could run "ls >> testfile.txt; exit" to output the results of ls to a file, and then have the terminal window close after it finishes executing.
You can use "jobs" to check if there are any processes running in the background.

Suppress command window when running console application on Windows

Is there a way to suppress showing the command window when running a console application on Windows XP?
Details: I am calling a (console-based) program from Vim. I would like to avoid the command window being shown every time I do this.
Try start /B <program name> to start the program without a new window.
Did you try shell.vim?
The xolox#shell#execute() function
This function enables other Vim
plug-ins to execute external commands
in the background (i.e.
asynchronously) without opening a
command prompt window on Windows.
i can't believe no one has suggested simply using :silent
for example, I have the following in my .vimrc (gvim on Win7)
"open windows explorer to the directory of the current file
:map <leader>ex :silent !Explorer %:p:h<CR>
When I didn’t want to see the output of external commands called from the Vim command line, I would prepend them with :silent. However, this results in a command window momentarily flashing on screen when running GVim under MS Windows. After a short while, I got annoyed by this behaviour so I researched alternative solutions (which is how I came across this question).
The best solution I came up with was to use Vim’s inbuilt system function which runs shell commands without opening an external command window. While the output of the shell command is not printed, its exit status is conveniently available via v:shell_error. It also has the advantage that it’s portable across (all) platforms.
Example (the echo statement should print 0 if C:\Windows exists):
call system("dir c:\windows")
echo v:shell_error
You could maybe use some autohotkey script of this kind:
Loop {
WinWait, my command window title
WinHide
}
I was trying to use git-bash as my shell from vim on Windows but having the command prompt open whenever a command was run, as you described. My eventual solution was to install the plugin xolox/vim-shell and add the following snippet to .vimrc:
if has('win32')
set shell=bash\ -c
set shellcmdflag=
set shellxquote='
set shellquote=
set shellredir=>
set noshelltemp "This prevents an external window from opening.
endif
This utility will also do the job:
http://www.ntwind.com/software/utilities/hstart.html

Resources