You are not logged in.

#1 2014-07-19 16:34:51

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,687
Website

run script to background wo/ showing the pid and done status [SOLVED]

I have a little script I wrote that I execute in my ~/.zshrc that I would like to run in the background without printing out the pid of the background process and the done status.  Is this possible?

Example:

<< ~/.zshrc is sourced and it runs this line>>
<< ~/bin/check& >>
[1] 13047
grtaysky@host ~ %
[1]  + 13047 done       ~/bin/check

What I want to see is:

<< ~/.zshrc is sourced and it runs this line>>
<< ~/bin/check& >>
grtaysky@host ~ %

Last edited by graysky (2014-07-20 10:32:02)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2014-07-19 17:07:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: run script to background wo/ showing the pid and done status [SOLVED]

( your command & ) >/dev/null 2>&1

I've just revised my "hush" function from the former to the latter here to get just this same result.  I've been testing it and it works well (in bash):

#hush() {
#	setsid $@ >/dev/null 2>&1 &
#}
hush() {
	(setsid $@ >/dev/null 2>&1 &) >/dev/null 2>&1
}

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2014-07-19 17:16:15

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: run script to background wo/ showing the pid and done status [SOLVED]

zshmisc(1) wrote:

If a job is started with `&|' or `&!', then that job is immediately disowned.  After startup, it does not have a place in the job table, and is not subject to the job control features described here.

Printing is part of job control, so this should do the trick.

Offline

#4 2014-07-20 02:39:38

Saint0fCloud
Member
Registered: 2009-03-31
Posts: 137

Re: run script to background wo/ showing the pid and done status [SOLVED]

To add to the other solutions, in order to specifically disable job control

setopt nomonitor

Although I'd assume you'd just want to disable it temporarily so that should probably be declared inside an anonymous function

Offline

#5 2014-07-20 03:09:08

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: run script to background wo/ showing the pid and done status [SOLVED]

Trilby wrote:
( your command & ) >/dev/null 2>&1

I've just revised my "hush" function from the former to the latter here to get just this same result.  I've been testing it and it works well (in bash):

#hush() {
#	setsid $@ >/dev/null 2>&1 &
#}
hush() {
	(setsid $@ >/dev/null 2>&1 &) >/dev/null 2>&1
}

Hmm... why do you background it? Isn't `setsid "$@" > /dev/null 2>&1` enough?


This silver ladybug at line 28...

Offline

#6 2014-07-20 10:31:21

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,687
Website

Re: run script to background wo/ showing the pid and done status [SOLVED]

Raynman wrote:
zshmisc(1) wrote:

If a job is started with `&|' or `&!', then that job is immediately disowned.  After startup, it does not have a place in the job table, and is not subject to the job control features described here.

Printing is part of job control, so this should do the trick.

Perfect!  Thank you!  Also, thanks to everyone else who replied with solutions.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#7 2014-07-20 11:11:40

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: run script to background wo/ showing the pid and done status [SOLVED]

lolilolicon wrote:

why do you background it? Isn't `setsid "$@" > /dev/null 2>&1` enough?

Indeed it is - I don't think I used to background it - I think that poped up in the revisions to add the ( ) subshell.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB