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

Process.run does not respect environment on Windows #38974

Closed
ghost opened this issue Oct 18, 2019 · 3 comments
Closed

Process.run does not respect environment on Windows #38974

ghost opened this issue Oct 18, 2019 · 3 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. area-documentation Prefer using 'type-documentation' and a specific area label. library-io P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team

Comments

@ghost
Copy link

ghost commented Oct 18, 2019

I'm observing some inconsistencies in behaviour when using Process.run(..) on Windows as follows:

When I run the below I get "ProcessException: The system cannot find the file specified.":

  Map<String, String> env = {'PATH': 'C:\\src\\'};
  result = await Process.run('hello.bat', [], environment: env);
  print(result.stdout);

This is unexpected as I can otherwise run the executable fine when I either run directly, without setting PATH:

  ProcessResult result;
  result = await Process.run('C:\\src\\hello.bat', []);
  print(result.stdout);

Or run it with PATH but with runInShell:

  Map<String, String> env = {'PATH': 'C:\\src\\'};
  result = await Process.run('hello.bat', [], environment: env, runInShell: true);
  print(result.stdout);

This indicates to me that it is able to run the process fine, and even pass the environment along in some cases - just not in the non-runInShell case, which seems like a bug.

@ghost ghost added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io labels Oct 18, 2019
@ghost
Copy link
Author

ghost commented Oct 18, 2019

FWIW, the failing example above appears to work fine one other platforms.

@ghost ghost changed the title Process.run on does not respect environment on Windows Process.run does not respect environment on Windows Oct 18, 2019
dart-bot pushed a commit that referenced this issue Oct 18, 2019
Bug: #38974
Change-Id: I5fafb29252f20a536b5543d309ddeb4ccd3421ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122145
Auto-Submit: Clement Skau <cskau@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
dart-bot pushed a commit that referenced this issue Oct 21, 2019
Bug: #38974
Change-Id: I5fafb29252f20a536b5543d309ddeb4ccd3421ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122145
Auto-Submit: Clement Skau <cskau@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
@brianquinlan brianquinlan added area-documentation Prefer using 'type-documentation' and a specific area label. P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team labels Dec 27, 2022
@brianquinlan
Copy link
Contributor

The CreateProcess documentation says:

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.
3. The 32-bit Windows system directory. Use the [GetSystemDirectory](https://learn.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getsystemdirectorya) function to get the path of this directory.
4. The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.
5. The Windows directory. Use the [GetWindowsDirectory](https://learn.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getwindowsdirectorya) function to get the path of this directory.
6. The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the [ShellExecute](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/axe/shellexecute) function.

My interpretation is that PATH refers to the PATH environment variable of the parent process.

Python uses the same approach that we do and they have a big warning block of documentation:
image

We should probably do the same i.e. suggest using a full path when runInShell=false.

copybara-service bot pushed a commit that referenced this issue Jan 9, 2023
…t|run)

Bug:#38974
Change-Id: I0d9bfd5726f8ad2c901e5d42f2bc79b636b9841b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278480
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
@brianquinlan
Copy link
Contributor

I improved the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. area-documentation Prefer using 'type-documentation' and a specific area label. library-io P2 A bug or feature request we're likely to work on triaged Issue has been triaged by sub team
Projects
None yet
Development

No branches or pull requests

1 participant