| delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| X-SWARE-Spam-Status: | No, hits=-0.4 required=5.0 tests=AWL,BAYES_00,RCVD_NUMERIC_HELO,SPF_HELO_PASS,T_RP_MATCHES_RCVD |
| X-Spam-Check-By: | sourceware.org |
| To: | cygwin AT cygwin DOT com |
| connect(): | No such file or directory |
| From: | Oleksandr Gavenko <gavenko AT bifit DOT com DOT ua> |
| Subject: | How you wrote wrapper around Cygwin scripts? |
| Date: | Thu, 03 Jun 2010 16:09:29 +0300 |
| Lines: | 104 |
| Message-ID: | <hu89i9$raf$1@dough.gmane.org> |
| Mime-Version: | 1.0 |
| User-Agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 |
| X-IsSubscribed: | yes |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Id: | <cygwin.cygwin.com> |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
| Note-from-DJ: | This may be spam |
For example Mercurial VCS hg distributed as python script.
To able invoke hg from cmd.exe (I some times use Far file manager
and all time native GNU Emacs) I wrote wrapper:
$ cat /bin/hg.bat
@echo off
python /bin/hg %*
This script work fine except case then one of argument
contain new line (line feed) char. This used by GNU Emacs
then commited changes (in term of sh script):
$ hg ci -m 'Multy
line nsg' myfile.c
%* in bat file truncate command line arguments to first occurence of
new line, so really invoked command look like:
cmd> hg ci -m Multy
- message truncated and file list removed (so committed all changed
file instead one specified).
I need analog of POSIX sh:
#!/bin/sh
prog --additional-opt "$@"
"$@" - special syntax to pass all args unchanged.
But in must be Windows solution (be Windows executable).
I see for WSH.
WBScript/JScript are runnable script like .bat, but seems unfortunelly
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("printarg -a d:/tmp/.log a b c")
reinvoke cmd.exe for Exec("...") call.
So I temporary use such solution
(like in Busybox script name get from argv[0]):
int main(int argc, char **argv)
{
char cmd[MAX_STR_LEN] = "";
char **cmdarg = malloc((argc+1) * sizeof(char *));
char *start, *end;
start = strrchr(*argv, '/');
if (start)
start++;
else
start = *argv;
end = strrchr(*argv, '.');
if (!end)
end = *argv + strlen(*argv);
memcpy(cmd, start, end - start);
cmd[end - start] = '\0';
for (int i = 0; i < argc; i++)
cmdarg[i] = argv[i];
cmdarg[argc] = NULL;
return execvp(cmd, cmdarg);
}
When compile this prog with depends on cygwin1.dll, execvp first search
for scripts before appending .exe suffix. That I need! So I do
$ gcc -o cygrun.exe cygrun.c
$ install -m 755 cygrun /bin/hg.exe
$ cd /hg-repo
$ hg.exe st 'multi xxx
yyy line'
multi xxx
yyy line: No such file or directory
As we can see multiline args correctly passed to hg python script.
But I recently posted about truble in native GNU Emacs (which build
with mingw runtime) when it invoke .exe which linked with cygwin1.dll
(both CYGWIN_NT-5.1 1.7.2s(0.225/5/3) 20100318
and CYGWIN_NT-5.1 1.5.25(0.156/4/2) 2007-12-14 as say uname -a).
When Emacs built with mingw runtime and call its
'call-process' lisp function in uses open/openp C func
(I have bad Emacs source code knowledge so can miss here).
If executable which passed to open func built with Cygwin runtime
it remove some occurences of '{' and '}' chars from executable argv.
At all it useful have ability invoke Cygwin scripts with wrapper
which correctly passed argument to script, but I don't know how make it.
Solution like <script>.bat or <script>.exe for <script> are best
as you don't need rewrite/reconfigure 3th party program.
--
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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |