This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

How you wrote wrapper around Cygwin scripts?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]