<p>In Unix, at least, "check, then act" is generally considered unwise:<br>
1. Something can go wrong between checking and acting.<br>
2. You might not be checking the right thing(s). In this case, the fact that the file exists is not useful if you don't have permission to execute it. You may not be able to determine whether you have the appropriate permissions without fairly deep manipulation of ACLs.<br>
3. Even if the OS has the info at hand, making the system call(s) necessary to get it is not free. Various non-free things happen every time control passes between user-space and kernel-space.</p>
<div class="gmail_quote">On Aug 13, 2012 4:17 AM, "Andrew Cowie" <<a href="mailto:andrew@operationaldynamics.com">andrew@operationaldynamics.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sun, 2012-08-12 at 23:18 -0700, Evan Laforge wrote:<br>
> Yes, I ran into the same thing a while back. The problem is that the<br>
> subprocess has already been forked off before it runs exec() and finds<br>
> out the file doesn't exist.<br>
<br>
Given how astonishingly common it is to pass an invalid executable name<br>
and/or path, wouldn't it be worth doing a quick probe to see if the file<br>
exists before createProcess actually forks?<br>
<br>
[It's not like the effort the OS is going to do for the stat is going to<br>
be thrown away; whether that call pulls it up off of disk or the one<br>
after the fork that exec will do doesn't matter]<br>
<br>
AfC<br>
Sydney<br>
<br>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div>