Skip to content

Using postpositional & (control operator) rather than Start-Job results in different current location (working directory) #4267

Closed

Description

Steps to reproduce

Set-Location /

$j = $pwd & Receive-Job -AutoRemoveJob -Wait $j

$j = Start-Job { $pwd }; Receive-Job -AutoRemoveJob -Wait $j

Expected behavior

/    # on Windows: C:\
/

Actual behavior

/
/home/jdoe   # on Linux; on macOS: /User/jdoe; on Windows: C:\Users\jdoe\Documents

Environment data

PowerShell Core v6.0.0-beta.4 on macOS 10.12.5
PowerShell Core v6.0.0-beta.4 on Ubuntu 16.04.2 LTS
PowerShell Core v6.0.0-beta.4 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)

Activity

  1. added
    Issue-Discussion
    on Jul 17, 2017
  2. added
    Resolution-By Design
    and removed
    Issue-Discussion
    on Jul 18, 2017
  3. BrucePay commented on Jul 18, 2017

    @BrucePay
    Collaborator

    This is by design. While & uses Start-Job under the covers, it is intended to mimic the *nix behavior which runs the background process in the current directory.

  4. mklement0 commented on Jul 18, 2017

    @mklement0
    ContributorAuthor

    Understood. Please make sure that the difference is documented.

  5. mklement0 commented on Aug 8, 2017

    @mklement0
    ContributorAuthor

    Speaking of mimicking *nix behavior: more things worth documenting:

    From what I can tell, PowerShell's jobs are fundamentally different from Bash's (do tell if I'm missing something - I'm not too familiar with PS jobs):

    • They can only be run "batch"-style with no interactive user input supported (if you send a Bash script to the background with a PS job, for instance, and that script tries to read from (non-redirected) stdin, it will simply encounter EOF (nothing to read) and proceed with empty input. By contrast, Bash would "stop" (suspend) such a script, allowing it to be brought to the foreground via job control to then supply the input interactively.)

    • They never output directly to the invoking terminal.

    Generally, PS has no equivalent to Bash's job control with respect to bringing jobs to the foreground / sending them to the background / "stopping" (suspending) and resuming them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-By Design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions