Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #347 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

Not able to run ar via Process

Reported by: larsivi Assigned to: jcomellas
Priority: major Milestone: Documentation
Component: Documentation Version:
Keywords: Cc: kris, sean

Description

I'm having several problems, so I'm not entirely sure about what is what, but the program (when compiled with DMD, using GDC results in same error as in #345)

import tango.sys.Process;
import tango.io.Stdout;

int main()
{
    auto ar = new Process("ar rs libtango.a *.o", null);
    ar.execute();
    Stdout.conduit.copy(ar.stdout);
    Stderr.conduit.copy(ar.stderr);
    auto result = ar.wait();
    if (result.reason != Process.Result.Exit) {
        Stderr("Was not able to create library").newline;
        Stdout("Reason is ")(result.reason).newline;
        return 1;
    }


    return 0;
}

prints

ar: creating libtango.a ar: *.o: No such file or directory

when run from a directory with lot's of .o files. Running the command from shell works fine.

Using explicit filenames instead of *.o works with this example.

If it is a documentation issue, please document.

Change History

03/22/07 14:47:46 changed by jcomellas

  • cc set to kris, sean.
  • status changed from new to assigned.

This happens because we're not doing wildcard expansion on POSIX platforms. Should we support wildcard expansion in this class? If so, we have 2 options:

  1. Change the Process class so that child processes are created by using the Unix shell (i.e. what the system() function does in C).
  2. Add code to perform the wildcard expansion in the Process class.

A way to easily fix this problem would be to change the line that says:

auto ar = new Process("ar rs libtango.a *.o", null);

to

auto ar = new Process("/bin/sh \"ar rs libtango.a *.o\"", null);

03/22/07 19:11:45 changed by sean

For what it's worth, Win32 requires the executing process to he "cmd.exe" if the command is a feature built into the shell (which on Win32 includes file copying, deletion, etc). With this in mind, it may actually be more consistent to leave things as they are now, though the behavior is somewhat non-intuitive.

03/23/07 04:49:12 changed by larsivi

  • type changed from defect to enhancement.
  • component changed from Core Functionality to Documentation.
  • milestone changed from 0.97 RC 1 to Documentation.

Yes, Kris (and I) agree. There is no simple way to do this crossplatform just yet - at least not without more coupling. I think we should just document the most common pitfalls when using the process class and eventually also how one might use Tango features to get to it.

03/26/07 12:01:03 changed by xammy

If you decide to implement it, using the first way (calling /bin/sh automatically), please remember, that this includes a double-fork(), one for calling /bin/sh and one for calling the specified binary. As fork() is somewhat slow (e.g. compared to threads), this should be avoided. So in my opinion, processing wildcards in Tango is preferrable.

just my 2 cents

04/03/07 22:09:26 changed by jcomellas

  • status changed from assigned to closed.
  • resolution set to fixed.

File globbing will not be implemented for the time being.