www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3120] New: std.process.execv() pass arguments to programm incorrectly

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3120

           Summary: std.process.execv() pass arguments to programm
                    incorrectly
           Product: D
           Version: 2.030
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: golovanov_alexey mail.ru


Phobos in DMD 2.030 and DMD 1.045 on Windows XP SP3:

function std.process.execv(in string pathname, in immutable(char)[][] argv)
don't pass argv parameters to executed program correctly. First element of argv
not passed (replaced by program name, or removed).

Short example - caller.exe should run called.exe with parameters "arg1",
"arg2", "arg3", then called.exe should save passed parameters into log file:

/*** begin file caller.d */
import std.process;

void main()
{
  string[] args = ["arg1", "arg2", "arg3"];
  std.process.execv("called.exe", args);
}
/*** end file caller.d */


/*** begin file called.d */
import std.file;
import std.string;

void main(string[] args)
{
  string s = std.string.join(args, " ");
  std.file.write("called.log", s);
}
/*** end file called.d */

In Windiws XP environment called.log will contain line:
"called.exe arg2 arg3"

but expected:
"called.exe arg1 arg2 arg3"

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 01 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3120






PDT ---
Created an attachment (id=408)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=408)
caller program using std.process.execv()

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 01 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3120






PDT ---
Created an attachment (id=409)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=409)
called programm, received parameters

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 01 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3120






PDT ---
this behaviour repeated in DMD 2.031

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 09 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3120


Masahiro Nakagawa <repeatedly gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |repeatedly gmail.com



13:36:35 PDT ---
This behavior is caused by dmc(I tested on Windows XP).

called.c
-----
#include <stdio.h>

int main(int argc, char* argv[])
{
    int i = 0;

    for (; i < argc; i++)
        printf("%s ", argv[i]);
}
-----

caller.c
-----
#include <stdlib.h>

int main()
{
    const char* const argv[] = {"a1", "a2", "a3", NULL};
    execv("called.exe", argv);
    return 0;
}
-----

dmc prints "called.exe a2 a3" but gcc prints "a1 a2 a3". I think expected
behavior is gcc result(not "called.exe arg1 arg2 arg3").

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 28 2010