* Hiding console when running Cygwin utility from Task Scheduler. @ 2017-08-02 16:06 Oleksandr Gavenko 2017-08-02 19:21 ` Brian Inglis 2017-08-07 17:05 ` Andrey Repin 0 siblings, 2 replies; 10+ messages in thread From: Oleksandr Gavenko @ 2017-08-02 16:06 UTC (permalink / raw) To: cygwin 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? -- http://defun.work/ -- 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Hiding console when running Cygwin utility from Task Scheduler. 2017-08-02 16:06 Hiding console when running Cygwin utility from Task Scheduler Oleksandr Gavenko @ 2017-08-02 19:21 ` Brian Inglis 2017-08-02 23:41 ` Oleksandr Gavenko 2017-08-07 17:05 ` Andrey Repin 1 sibling, 1 reply; 10+ messages in thread From: Brian Inglis @ 2017-08-02 19:21 UTC (permalink / raw) To: cygwin 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Hiding console when running Cygwin utility from Task Scheduler. 2017-08-02 19:21 ` Brian Inglis @ 2017-08-02 23:41 ` Oleksandr Gavenko 2017-08-03 5:21 ` Brian Inglis 0 siblings, 1 reply; 10+ messages in thread From: Oleksandr Gavenko @ 2017-08-02 23:41 UTC (permalink / raw) To: cygwin On 2017-08-02, Brian Inglis wrote: > 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. That is not the case for: > How can I prevent console to be shown when bash started from Task Scheduler? Closing of stdin / stdout / stderr is task for external process (like CRON) even on UNIX. With simple: #include <stdio.h> #include <unistd.h> int main(int argc, char **argv) { fclose(stdin); fclose(stdout); fclose(stderr); sleep(10); return 0; } in Task Scheduler I see console window and supporting conhost.exe process. OK. I know about run.exe from package: run sdesc: "Launch cmdline programs with hidden console" ldesc: "Launch cmdline programs with hidden console" category: Base requires: cygwin version: 1.3.4-2 I tried: $ cp /bin/run.exe ~/usr/bin/runbash.exe and provide path to ~/usr/bin/runbash.exe in Task Scheduler. Console window still flashes. With my tiny test utility: $ cp /bin/run.exe ~/usr/bin/runxtest.exe it flashes too from Task Scheduler but for a moment not 10 sec )) Same if I run by Win+R: $ run xtest My goal to avoid any splashes on screen and possible keyboard focus stealing from sudden task execution. -- http://defun.work/ -- 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Hiding console when running Cygwin utility from Task Scheduler. 2017-08-02 23:41 ` Oleksandr Gavenko @ 2017-08-03 5:21 ` Brian Inglis 2017-08-03 11:43 ` Oleksandr Gavenko 0 siblings, 1 reply; 10+ messages in thread From: Brian Inglis @ 2017-08-03 5:21 UTC (permalink / raw) To: cygwin On 2017-08-02 17:40, Oleksandr Gavenko wrote: > On 2017-08-02, Brian Inglis wrote: >> 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. > > That is not the case for: > > How can I prevent console to be shown when bash started from Task > Scheduler? > > Closing of stdin / stdout / stderr is task for external process (like CRON) > even on UNIX. I believe that conhost, mintty, ptys, cron, and Cygwin program startup open handles for stdin, stdout, stderr to talk on, as those are assumed to be available by most programs, rather than closing anything, which could terminate program execution. > With simple: > > #include <stdio.h> > #include <unistd.h> > > int main(int argc, char **argv) { > fclose(stdin); > fclose(stdout); > fclose(stderr); > > sleep(10); > > return 0; > } > > in Task Scheduler I see console window and supporting conhost.exe process. > > OK. I know about run.exe from package: > > run > sdesc: "Launch cmdline programs with hidden console" > ldesc: "Launch cmdline programs with hidden console" > category: Base > requires: cygwin > version: 1.3.4-2 > > I tried: > > $ cp /bin/run.exe ~/usr/bin/runbash.exe > > and provide path to ~/usr/bin/runbash.exe in Task Scheduler. Console window > still flashes. > > With my tiny test utility: > > $ cp /bin/run.exe ~/usr/bin/runxtest.exe > > it flashes too from Task Scheduler but for a moment not 10 sec )) > > Same if I run by Win+R: > > $ run xtest Cygwin run allows you to run a Windows GUI program with a hidden console window. I am never certain whether any Cygwin reference to Windows console and GUI programs includes or excludes Cygwin command line and X Windows programs. > My goal to avoid any splashes on screen and possible keyboard focus stealing > from sudden task execution. I never see any windows or conhost processes running Cygwin Scheduled Tasks with the previous suggestions and these settings: >> 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. where the first may be most significant in this case; the second avoids you having to enter your password any time you make a change; the third is just for luck! ;^> YMMV -- 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Hiding console when running Cygwin utility from Task Scheduler. 2017-08-03 5:21 ` Brian Inglis @ 2017-08-03 11:43 ` Oleksandr Gavenko 2017-08-03 13:05 ` cyg Simple 0 siblings, 1 reply; 10+ messages in thread From: Oleksandr Gavenko @ 2017-08-03 11:43 UTC (permalink / raw) To: cygwin On 2017-08-02, Brian Inglis wrote: > I believe that conhost, mintty, ptys, cron, and Cygwin program startup open > handles for stdin, stdout, stderr to talk on, as those are assumed to be > available by most programs, rather than closing anything, which could terminate > program execution. > Small correction about `conhost`: https://blogs.technet.microsoft.com/askperf/2009/10/05/windows-7-windows-server-2008-r2-console-host/ https://blogs.msdn.microsoft.com/reiley/2012/09/13/windows-8-and-conhost-exe/ It is native Windows app. I believe that it is responsible to drawing native console and I want to hide it. > Cygwin run allows you to run a Windows GUI program with a hidden console window. > I think situation a bit different. run.exe is able to "hide" console of console app. Cygwin compiles each app as console as GUI app have no access to stdin/stdout and can't attach to any console, as state run(1): Windows programs are either GUI programs or console programs. When started console programs will either attach to an existing console or create a new one. GUI programs can never attach to an exiting console. There is no way to attach to an existing console but hide it if started as GUI program. >> My goal to avoid any splashes on screen and possible keyboard focus stealing >> from sudden task execution. > > I never see any windows or conhost processes running Cygwin Scheduled Tasks with > the previous suggestions and these settings: > >>> 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. > > where the first may be most significant in this case; Thanks! That is. When I change from: [x] run only when user logged in to: [x] run whether user is logged on or not I don't see that temporary console window. I was going to check what happen with Cygwin app launched from nssm and see comment: 2017-04-26: Users of Windows 10 Creators Update should use prelease build 2.2.4-101 to avoid an issue with services failing to start. If for some reason you cannot use that build you can also set AppNoConsole=1 in the registry, noting that applications which expect a console window may behave unexpectedly. https://nssm.cc/download So Microsoft recently changed something in its console related API... -- http://defun.work/ -- 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Hiding console when running Cygwin utility from Task Scheduler. 2017-08-03 11:43 ` Oleksandr Gavenko @ 2017-08-03 13:05 ` cyg Simple 2017-08-03 14:09 ` Oleksandr Gavenko 0 siblings, 1 reply; 10+ messages in thread From: cyg Simple @ 2017-08-03 13:05 UTC (permalink / raw) To: cygwin Why did no one mention: $ /usr/bin/nohup --help Usage: /usr/bin/nohup COMMAND [ARG]... or: /usr/bin/nohup OPTION Run COMMAND, ignoring hangup signals. --help display this help and exit --version output version information and exit If standard input is a terminal, redirect it from an unreadable file. If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise. If standard error is a terminal, redirect it to standard output. To save output to FILE, use '/usr/bin/nohup COMMAND > FILE'. NOTE: your shell may have its own version of nohup, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Full documentation at: <http://www.gnu.org/software/coreutils/nohup> or available locally via: info '(coreutils) nohup invocation' ------------ If you use nohup you'll need to specify the absolute paths or be sure to introduce Cygwin executable directory on your Windows PATH which we discourage. -- cyg Simple -- 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Hiding console when running Cygwin utility from Task Scheduler. 2017-08-03 13:05 ` cyg Simple @ 2017-08-03 14:09 ` Oleksandr Gavenko 0 siblings, 0 replies; 10+ messages in thread From: Oleksandr Gavenko @ 2017-08-03 14:09 UTC (permalink / raw) To: cygwin On 2017-08-03, cyg Simple wrote: > Why did no one mention: > > $ /usr/bin/nohup --help Because we under Windows and all Cygwin binaries built as console apps and show console window. You may check it yourself: Win+R nohup yes RET It is not easy to hide console. You need to build GUI program that will hide console of next running program or something like that. My knowledge is very limiting regarding Windows. Under Unix nohup detaches app from controlling terminal so you may leave terminal session and program isn't terminated by SIGHUP signal. -- http://defun.work/ -- 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Hiding console when running Cygwin utility from Task Scheduler. 2017-08-02 16:06 Hiding console when running Cygwin utility from Task Scheduler Oleksandr Gavenko 2017-08-02 19:21 ` Brian Inglis @ 2017-08-07 17:05 ` Andrey Repin 2017-08-07 17:36 ` Oleksandr Gavenko 1 sibling, 1 reply; 10+ messages in thread From: Andrey Repin @ 2017-08-07 17:05 UTC (permalink / raw) To: Oleksandr Gavenko, cygwin Greetings, Oleksandr Gavenko! > 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? Do not start tasks as current user. Or use wrapper that prevent console window creation in first place. -- With best regards, Andrey Repin Monday, August 7, 2017 19:51:43 Sorry for my terrible english... -- 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Hiding console when running Cygwin utility from Task Scheduler. 2017-08-07 17:05 ` Andrey Repin @ 2017-08-07 17:36 ` Oleksandr Gavenko 2017-08-08 0:05 ` Andrey Repin 0 siblings, 1 reply; 10+ messages in thread From: Oleksandr Gavenko @ 2017-08-07 17:36 UTC (permalink / raw) To: cygwin On 2017-08-07, Andrey Repin wrote: >> How can I prevent console to be shown when bash started from Task Scheduler? > > Do not start tasks as current user. Or use wrapper that prevent console > window creation in first place. Brian Inglis told about this solution: >> (o) Run whether user is logged on or not radio button The problem only if you run as: [x] run only when user logged in -- http://defun.work/ -- 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Hiding console when running Cygwin utility from Task Scheduler. 2017-08-07 17:36 ` Oleksandr Gavenko @ 2017-08-08 0:05 ` Andrey Repin 0 siblings, 0 replies; 10+ messages in thread From: Andrey Repin @ 2017-08-08 0:05 UTC (permalink / raw) To: Oleksandr Gavenko, cygwin Greetings, Oleksandr Gavenko! > On 2017-08-07, Andrey Repin wrote: >>> How can I prevent console to be shown when bash started from Task Scheduler? >> >> Do not start tasks as current user. Or use wrapper that prevent console >> window creation in first place. > Brian Inglis told about this solution: >>> (o) Run whether user is logged on or not radio button > The problem only if you run as: > [x] run only when user logged in That's a tangential setting. -- With best regards, Andrey Repin Tuesday, August 8, 2017 02:56:40 Sorry for my terrible english... -- 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2017-08-08 0:05 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-08-02 16:06 Hiding console when running Cygwin utility from Task Scheduler Oleksandr Gavenko 2017-08-02 19:21 ` Brian Inglis 2017-08-02 23:41 ` Oleksandr Gavenko 2017-08-03 5:21 ` Brian Inglis 2017-08-03 11:43 ` Oleksandr Gavenko 2017-08-03 13:05 ` cyg Simple 2017-08-03 14:09 ` Oleksandr Gavenko 2017-08-07 17:05 ` Andrey Repin 2017-08-07 17:36 ` Oleksandr Gavenko 2017-08-08 0:05 ` Andrey Repin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).