Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createProcess function is can't exec a *.cmd or *.bat file #140

Closed
taiju opened this issue Nov 16, 2018 · 9 comments
Closed

createProcess function is can't exec a *.cmd or *.bat file #140

taiju opened this issue Nov 16, 2018 · 9 comments

Comments

@taiju
Copy link

taiju commented Nov 16, 2018

-- Sorry, I'm poor English.

createProcess function is can't exec a *.cmd or *.bat file.

I can exec foo command when foo.cmd is placed of system environment variable paths. However, createProcess function is can't exec foo. (foo.cmd too)

It catch an error that error message is does not exist (No such file or directory).

reproduction screenshot

ps

about this problem

This is not usually a problem. However, It may be a problem. For example, some of the commands built by NodeJS (with NPM) are wrapped with .cmd file.

Concretely, I'm facing this problem at here.

@snoyberg
Copy link
Collaborator

I don't understand why the first example from the command line itself worked. If foo.cmd is in the bin subdirectory, how does the shell find it? Is there a PATH env var set? Is that env var being passed in to ghci?

Similarly, does running proc "foo.cmd" instead work?

@taiju
Copy link
Author

taiju commented Nov 19, 2018

There is Path env var set. bin subdirectory is included it.

env-path

the env var passed in to ghci.

getenv

proc "foo.cmd" instead work.

foo cmd

Although it can be executed on the command line, it can not be executed on the createProcess in some cases (For example, commands that wrapped by npm).

results

指定されたパスが見つかりません means "The specified path can not be found".

@snoyberg
Copy link
Collaborator

OK, so narrowing this down further, it seems like the problem is: given a plain executable name like foo, the process package will find foo.exe if it exists in directories of the PATH, but it will not find foo.bat and foo.cmd. Is that accurate?

@taiju
Copy link
Author

taiju commented Nov 19, 2018

Yes, it is accurate.
Additionally, createProcess can't resolve cwd path in foo.cmd well such as a screen shot above.

@snoyberg
Copy link
Collaborator

I've looked into the source code on Windows. Ultimately, we're passing the command line to the CreateProcess function, which seems to document this behavior:

If the file name does not contain an extension, .exe is appended. Therefore, if the file name extension is .com, this parameter must include the .com extension. If the file name ends in a period (.) with no extension, or if the file name contains a path, .exe is not appended.

(From MSDN on CreateProcessA.)

I don't see which screen shot demonstrates the claim about the CWD path. I will note that on POSIX systems, that's the expected behavior. However, from the same MSDN docs, it should work as you expect on Windows:

If the file name does not contain a directory path, the system searches for the executable file in the following sequence:

  1. The directory from which the application loaded.
  2. The current directory for the parent process.

@taiju
Copy link
Author

taiju commented Nov 19, 2018

I don't see which screen shot demonstrates the claim about the CWD path.

I'm sorry for bad explanation. Please see below.

path

I expected %~dp0 output result point to the path of foo.cmd. However, %~dp0 point to the ghci CWD path. (I couldn't found official informations of %~dp0.)

@snoyberg
Copy link
Collaborator

I'm going to guess in all of these cases, if you instead use shell (not proc), you get the behavior you're looking for. If that's the case, I would say that the library is acting as expected.

@taiju
Copy link
Author

taiju commented Nov 19, 2018

Thank you! shell is acting as expected!
I understood that the problem that I'm facing is not a System.Process library problem, but a System.Process library user side problem.

@snoyberg
Copy link
Collaborator

You're welcome, no problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants