X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:reply-to:subject:to:references:from:message-id
	:date:mime-version:in-reply-to:content-type
	:content-transfer-encoding; q=dns; s=default; b=j4AvhvSxrVfZ2frC
	gSEt4+8Jz+4Esy4XDdEBQ2tLfwhNDi5NQNRMlezdDr4ETX9LCZ2GjeIO4BioLhVs
	Ey0h99YpzRqyWPQgOanfw05P1VOYZ8g5fM5N8Zv/YGBalTQI8p/luhTMPEj7AUDu
	E5HPKIJzOdlhFbCCBZCD/UwqaBc=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:reply-to:subject:to:references:from:message-id
	:date:mime-version:in-reply-to:content-type
	:content-transfer-encoding; s=default; bh=DyrHYngUEw3QovXaEMuEJY
	dOUe4=; b=IW8nGHJnNjZmEJPDcZEatqVaBJzL4ZbqJZPeARjpTPJuS3Zgj5rqlB
	SWKy4tX4yB7ocYUl7SxZds6WGDmEL8vSKhBpE3IkSJdvC94AMHffhd4RUpUljQE3
	O2kIxymFJtvSzNYob4B0kKKDbh/lScVApXh5EDOPWe9XwcHhreSYc=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=UD:bash.exe, bash.exe, bashexe, Hx-languages-length:1529
X-HELO: smtp-out-no.shaw.ca
X-Authority-Analysis: v=2.2 cv=a+JAzQaF c=1 sm=1 tr=0 a=MVEHjbUiAHxQW0jfcDq5EA==:117 a=MVEHjbUiAHxQW0jfcDq5EA==:17 a=IkcTkHD0fZMA:10 a=OglgaO2ez55zPvxJ65cA:9 a=QEXdDO2ut3YA:10
Reply-To: Brian.Inglis@SystematicSw.ab.ca
Subject: Re: Hiding console when running Cygwin utility from Task Scheduler.
To: cygwin@cygwin.com
References: <86o9ryymx5.fsf@gavenkoa.example.com>
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
Message-ID: <a547973c-5175-9dc8-1b8a-55635e73983b@SystematicSw.ab.ca>
Date: Wed, 2 Aug 2017 13:21:46 -0600
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1
MIME-Version: 1.0
In-Reply-To: <86o9ryymx5.fsf@gavenkoa.example.com>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-CMAE-Envelope: MS4wfBh/1P5MobVrdAwQnVojVvV2Q9ATUkq5H21k5zg2e+pfvM+0p8NBtaKzg8ke6qi1n9g+hzhro6sWaZoyO5CszlGhnpN1+2qvcO1aLFEW65Lr7LUP/37w 1HQUiH0+YHqgnXOub+WmbbVFaQWsxiJU5NCVx1p3+g9jIpOslrnRfHjpNwoaocrllKEoybYhOV4rmQ==
X-IsSubscribed: yes

On 2017-08-02 10:06, Oleksandr Gavenko wrote:
> I prepared backup task in Bash script and added task to run it in Windows Task
> Scheduler:
>   Executable: c:\opt\cygwin\bin\bash.exe
>   Params: c:\home\backup\backup-job.bash
> Each time job run I see console screen. 'procmon' shown that it is::
>   \??\C:\Windows\system32\conhost.exe 0xffffffff -ForceV1
> Seems each Cygwin utility brings console into foreground. I also tested with:
>   c:\opt\cygwin\bin\yes.exe
> How can I prevent console to be shown when bash started from Task Scheduler?

Redirect all stdin from /dev/null, stdout, stderr to a log file in your script ,
like:
	#!/bin/bash
	prog=${0##*/}
	base=${prog%.*}
	log=/var/log/$base.log

	# do everything inside this wrapper
	{
		...
	} < /dev/null &> $log

or equivalent on each command if you don't have many.

Ensure you always use the correct hashbang path and the script is executable.

You might also want to change your Task Action Arguments to:
	-- /proc/cygdrive/c/home/backup/backup-job.bash
to indicate "--" end of options, there are no options, just args, and use Cygwin
paths for all file arguments.

You may also have to set the (o) Run whether user is logged on or not radio
button, [X] Do not store password..., and [X] Run with highest privileges check
boxes.

I have found it useful to Cygwin symlink all cron/Task scripts to
/usr/local/bin/ and use that path for all script jobs.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

