RE: how to embed shell script within a .BAT file
From: Achim Gratz Nellis, Kenneth writes: Jeremy's solution is closest to what I was looking for; however I need it to work from a networked, non-drive-mapped folder. (CMD.EXE doesn't like UNC paths.) I hadn't realized that I could pipe a script into bash. The solution to the UNC path problem is to put something PUSHD %~dp0 near the beginning of the script. That is if you really want to have .bat files and click on them in Explorer. Associating the shell scripts properly so that Explorer will hand them to Cygwin sounds like a better solution to me. BTW, works great! Here's the completed .BAT file preface with added error handling so the CMD window doesn't auto-close if the bash code exits with an error. @echo off set PATH=C:\cygwin64\bin;%PATH% PUSHD %~dp0 type %0 | sed 0,/^---BASH SCRIPT FOLLOWS---/ d; s/\r*$// | bash if errorlevel 1 pause exit ---BASH SCRIPT FOLLOWS--- ... I'll pursue associating a shell script with a file type when I have more time. --Ken Nellis -- 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
Re: how to embed shell script within a .BAT file
Greetings, Nellis, Kenneth! From: Achim Gratz Nellis, Kenneth writes: Jeremy's solution is closest to what I was looking for; however I need it to work from a networked, non-drive-mapped folder. (CMD.EXE doesn't like UNC paths.) I hadn't realized that I could pipe a script into bash. The solution to the UNC path problem is to put something PUSHD %~dp0 near the beginning of the script. That is if you really want to have .bat files and click on them in Explorer. Associating the shell scripts properly so that Explorer will hand them to Cygwin sounds like a better solution to me. BTW, works great! Here's the completed .BAT file preface with added error handling so the CMD window doesn't auto-close if the bash code exits with an error. @echo off set PATH=C:\cygwin64\bin;%PATH% PUSHD %~dp0 PUSHD %~dp0 But be aware, that you will lose the ability to run such script from different CWD. type %0 | sed 0,/^---BASH SCRIPT FOLLOWS---/ d; s/\r*$// | bash sed 0,/^---BASH SCRIPT FOLLOWS---/ d; s/\r*$// %~f0 | bash if errorlevel 1 pause exit That's nice for desktop application. But EXIT %ERRORLEVEL% would be more useful in general. And keep in mind: not everything can be run that way, unfortunately. Only interpreters accepting command stream from STDIN (such as bash). And you will lose the ability to pipe data to such script yourself. ---BASH SCRIPT FOLLOWS--- ... I'll pursue associating a shell script with a file type when I have more time. On a slightly unrelated note, please avoid naming your scripts .bat, when you are using extended CMD features. Not every .bat file interpreter supports a full range of bugs in CMD. -- WBR, Andrey Repin (anrdae...@yandex.ru) 11.11.2014, 22:35 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
RE: how to embed shell script within a .BAT file
From: Jeremy Bopp On 11/07/2014 03:26 PM, Nellis, Kenneth wrote: I'm tired of creating pairs of script files: a clickable .BAT file to invoke my shell script and then my shell script to do the actual work. I was wondering if any of the geniuses on this list have come up with a way to embed a shell script inside a clickable .BAT file. Something like this might do. It assumes you know the path to the Cygwin bin directory. Passing in arguments would be a bit more work and would probably be somewhat limited unless you have a small number of possible arguments. FYI, I don't have a Windows system readily available anymore, so this is untested. Shelly.bat: @echo off rem Put Cygwin bin directory into PATH set PATH=C:\cygwin\bin;%PATH% type %0 | sed 0,/^---BASH SCRIPT FOLLOWS---/ d; s/\r*$// | bash goto :eof ---BASH SCRIPT FOLLOWS--- echo $SHELL is alive ^Z Thanx to Jeremy, Andrey, and the others who responded. Jeremy's solution is closest to what I was looking for; however I need it to work from a networked, non-drive-mapped folder. (CMD.EXE doesn't like UNC paths.) I hadn't realized that I could pipe a script into bash. Andrey also suggested something that allows Windows-clickable script files, a strict requirement, bypassing the stated, but unnecessary requirement that it be a .BAT file, by associating a file type with bash. This would bypass the UNC issue, so may end up being the best solution for me. --Ken Nellis -- 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
Re: how to embed shell script within a .BAT file
Nellis, Kenneth writes: Jeremy's solution is closest to what I was looking for; however I need it to work from a networked, non-drive-mapped folder. (CMD.EXE doesn't like UNC paths.) I hadn't realized that I could pipe a script into bash. The solution to the UNC path problem is to put something PUSHD %~dp0 near the beginning of the script. That is if you really want to have .bat files and click on them in Explorer. Associating the shell scripts properly so that Explorer will hand them to Cygwin sounds like a better solution to me. Regards, Achim. -- +[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]+ SD adaptations for KORG EX-800 and Poly-800MkII V0.9: http://Synth.Stromeko.net/Downloads.html#KorgSDada -- 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
Re: how to embed shell script within a .BAT file
Greetings, Nellis, Kenneth! (CMD.EXE doesn't like UNC paths.) I hadn't realized that I could pipe a script into bash. reg ADD HKEY_CURRENT_USER\Software\Microsoft\Command Processor /f /v DisableUNCCheck /t REG_DWORD /d 1 And speaking of doesn't like, it only don't like it's own CWD to be UNC path. You can still start programs by full UNC path from CMD. Though, with correct settings (see above), the point is moot. -- WBR, Andrey Repin (anrdae...@yandex.ru) 10.11.2014, 21:56 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
Re: how to embed shell script within a .BAT file
On 11/10/2014 10:57 AM, Andrey Repin wrote: Greetings, Nellis, Kenneth! (CMD.EXE doesn't like UNC paths.) I hadn't realized that I could pipe a script into bash. reg ADD HKEY_CURRENT_USER\Software\Microsoft\Command Processor /f /v DisableUNCCheck /t REG_DWORD /d 1 And speaking of doesn't like, it only don't like it's own CWD to be UNC path. You can still start programs by full UNC path from CMD. Though, with correct settings (see above), the point is moot. -- WBR, Andrey Repin (anrdae...@yandex.ru) 10.11.2014, 21:56 Sorry for my terrible english... I always thought it odd that MS invents UNC's then fails to support them properly in their own tools. Try pushd on a UNC path... -- Andrew DeFaria http://defaria.com -- 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
Re: how to embed shell script within a .BAT file
Greetings, Andrew DeFaria! (CMD.EXE doesn't like UNC paths.) I hadn't realized that I could pipe a script into bash. reg ADD HKEY_CURRENT_USER\Software\Microsoft\Command Processor /f /v DisableUNCCheck /t REG_DWORD /d 1 And speaking of doesn't like, it only don't like it's own CWD to be UNC path. You can still start programs by full UNC path from CMD. Though, with correct settings (see above), the point is moot. I always thought it odd that MS invents UNC's then fails to support them properly in their own tools. Try pushd on a UNC path... Since migration to Win7, I'm using native symlinks, and pretty happy about it. I still occasionally hit the UNC path here and there from old shortcuts, but overall, it's all local filesystem. :b -- WBR, Andrey Repin (anrdae...@yandex.ru) 10.11.2014, 23:49 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
Re: how to embed shell script within a .BAT file
Greetings, Nellis, Kenneth! I'm tired of creating pairs of script files: a clickable .BAT file to invoke my shell script and then my shell script to do the actual work. google: cygwin shell wrapper script I posted mine in the mailing list not once, and it's not the only available solution. I was wondering if any of the geniuses on this list have come up with a way to embed a shell script inside a clickable .BAT file. It is technically possible to invoke specific processor for a bat file, but no Cygwin tools understand the necessary syntax. Your only option is to create proper association(s) for your favorite extensions. FTYPE unixshell.script=C:\Programs\Cygwin_64\bin\env.exe -- /bin/cygwrap.sh %1 %* ASSOC .sh=unixshell.script ASSOC .awk=unixshell.script ASSOC .pl=unixshell.script ASSOC .whatver=unixshell.script The wrapper is as simple as 8888 #!/bin/sh test -z $1 exit 1 /bin/env -- $(cygpath -au $1) ${@:2} 8888 Don't forget to add your favorite extensions to PATHEXT, else you won't be able to run them scripts from CMD. -- WBR, Andrey Repin (anrdae...@yandex.ru) 10.11.2014, 00:51 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
Re: how to embed shell script within a .BAT file
Greetings, Eric Blake! On 11/07/2014 10:26 PM, Nellis, Kenneth wrote: I'm tired of creating pairs of script files: a clickable .BAT file to invoke my shell script and then my shell script to do the actual work. I was wondering if any of the geniuses on this list have come up with a way to embed a shell script inside a clickable .BAT file. A quick google search for polyglot shell bat finds: http://www.spinellis.gr/blog/20100112/ Worst solution I've never seen. Starting from obvious limit of nine parameters and down to the less-than-manageable code gibberish. -- WBR, Andrey Repin (anrdae...@yandex.ru) 10.11.2014, 00:58 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
Re: how to embed shell script within a .BAT file
On Fri, Nov 7, 2014 at 4:26 PM, Nellis, Kenneth wrote: I'm tired of creating pairs of script files: a clickable .BAT file to invoke my shell script and then my shell script to do the actual work. I was wondering if any of the geniuses on this list have come up with a way to embed a shell script inside a clickable .BAT file. Isn't this as simple as adding the path to cygwin/bin to PATH and executing the commands you need? Or associate .sh extension to cygwin/bin/bash.exe then clicking will associate the correct shell. -- 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
Re: how to embed shell script within a .BAT file
On Mon, Nov 10, 2014 at 12:58:07AM +0300, Andrey Repin wrote: Greetings, Nellis, Kenneth! I'm tired of creating pairs of script files: a clickable .BAT file to invoke my shell script and then my shell script to do the actual work. google: cygwin shell wrapper script I posted mine in the mailing list not once, and it's not the only available solution. I'm curious. Why go through all of what you wrote when all you need to do is execute the shell script? I'm a Z-shell user and have a bunch of scripts that I run. Maybe the secret is not to try and start a script from within a command prompt. Start cygwin xterms. I have two that I start up after booting the system. The scripts are in my home/bin path, so they are found. It is as simple as that. It is true that they are not clickable, but entering the script name in the xterm also allows me to also include parameters/options. MB -- e-mail: vid...@vidiot.com | vid...@vidiot.net/~\ The ASCII 6082066...@email.uscc.net (140 char limit) \ / Ribbon Campaign Visit - URL: http://vidiot.com/ X Against http://vidiot.net/ / \ HTML Email What do you say Beckett. Wanna have a baby? - Castle to Det. Beckett How long have I been gone? Alexis after seeing Castle and Beckett w/ baby - Castle - 11/25/13 -- 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
Re: how to embed shell script within a .BAT file
Greetings, Mike Brown! I'm tired of creating pairs of script files: a clickable .BAT file to invoke my shell script and then my shell script to do the actual work. google: cygwin shell wrapper script I posted mine in the mailing list not once, and it's not the only available solution. I'm curious. Why go through all of what you wrote when all you need to do is execute the shell script? I'm a Z-shell user and have a bunch of scripts that I run. Scripts aren't executed in vacuum. And the question is not limited to SHELL scripts. Maybe the secret is not to try and start a script from within a command prompt. Start cygwin xterms. Why? I don't need no friggin xterm, I need to run a script. Is this a hard concept to grasp? I have two that I start up after booting the system. The scripts are in my home/bin path, so they are found. It is as simple as that. Simple as what? I don't understand, what two you have and what you are actually doing. It is true that they are not clickable, but entering the script name in the xterm also allows me to also include parameters/options. I don't know the name, I have a script that I want to run. Here. Now. Why can't I just click it? -- WBR, Andrey Repin (anrdae...@yandex.ru) 10.11.2014, 05:07 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
Re: how to embed shell script within a .BAT file
On Mon, Nov 10, 2014 at 05:10:00AM +0300, Andrey Repin wrote: Greetings, Mike Brown! I'm tired of creating pairs of script files: a clickable .BAT file to invoke my shell script and then my shell script to do the actual work. google: cygwin shell wrapper script I posted mine in the mailing list not once, and it's not the only available solution. I'm curious. Why go through all of what you wrote when all you need to do is execute the shell script? I'm a Z-shell user and have a bunch of scripts that I run. Scripts aren't executed in vacuum. And the question is not limited to SHELL scripts. True. I do not compile any programs, so anything that I need to run that is clickable are Windows programs. Maybe the secret is not to try and start a script from within a command prompt. Start cygwin xterms. Why? I don't need no friggin xterm, I need to run a script. Is this a hard concept to grasp? It is not, which I how I run my scripts, from an xterm command prompt. All of my scripts have have input, be it an option and/or file to work on. That is not easily done if the script were clickable. Sure, the script can ask for input, but that adds time to get it running. Starting it via the command line saves me lots of time. I also have scipts that are started via cron. Options are passed to the scripts from within the scron configuration file. I have two that I start up after booting the system. The scripts are in my home/bin path, so they are found. It is as simple as that. Simple as what? I don't understand, what two you have and what you are actually doing. Two xterms that are started by clicking on the shortcut that I created that points to the BAT file that starts an xterm. It is true that they are not clickable, but entering the script name in the xterm also allows me to also include parameters/options. I don't know the name, I have a script that I want to run. Here. Now. Why can't I just click it? You never have to supply your scripts with options and/or files to deal with? Entering the script name in the xterm is a lot faster than hunting down the name in explorer (the file manager) or a shortcut on the desktop. If you have a lot of scripts, your desktop can get cluttered real fast. Mine is cluttered enough with Windows programs that I use. I'm and old Unix guy that has grown up with the command line. I find it fast to use. There are those that hate the command line and prefer to onlty click on something to get it started. I guess that is where we differ. I've provided you with an option. Do with it as you will. MB -- e-mail: vid...@vidiot.com | vid...@vidiot.net/~\ The ASCII 6082066...@email.uscc.net (140 char limit) \ / Ribbon Campaign Visit - URL: http://vidiot.com/ X Against http://vidiot.net/ / \ HTML Email What do you say Beckett. Wanna have a baby? - Castle to Det. Beckett How long have I been gone? Alexis after seeing Castle and Beckett w/ baby - Castle - 11/25/13 -- 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
how to embed shell script within a .BAT file
I'm tired of creating pairs of script files: a clickable .BAT file to invoke my shell script and then my shell script to do the actual work. I was wondering if any of the geniuses on this list have come up with a way to embed a shell script inside a clickable .BAT file. --Ken Nellis -- 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
Re: how to embed shell script within a .BAT file
On 11/07/2014 10:26 PM, Nellis, Kenneth wrote: I'm tired of creating pairs of script files: a clickable .BAT file to invoke my shell script and then my shell script to do the actual work. I was wondering if any of the geniuses on this list have come up with a way to embed a shell script inside a clickable .BAT file. A quick google search for polyglot shell bat finds: http://www.spinellis.gr/blog/20100112/ -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: how to embed shell script within a .BAT file
On 11/07/2014 03:26 PM, Nellis, Kenneth wrote: I'm tired of creating pairs of script files: a clickable .BAT file to invoke my shell script and then my shell script to do the actual work. I was wondering if any of the geniuses on this list have come up with a way to embed a shell script inside a clickable .BAT file. Something like this might do. It assumes you know the path to the Cygwin bin directory. Passing in arguments would be a bit more work and would probably be somewhat limited unless you have a small number of possible arguments. FYI, I don't have a Windows system readily available anymore, so this is untested. Shelly.bat: @echo off rem Put Cygwin bin directory into PATH set PATH=C:\cygwin\bin;%PATH% type %0 | sed 0,/^---BASH SCRIPT FOLLOWS---/ d; s/\r*$// | bash goto :eof ---BASH SCRIPT FOLLOWS--- echo $SHELL is alive ^Z -Jeremy -- 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
Re: how to embed shell script within a .BAT file
Do you really need to embed the script *within* the file? It would be straightforward to *invoke* a script from the file by something along the lines of: bash -c script in the .bat file ... Eliot Moss -- 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