Skip to content
This repository has been archived by the owner on Feb 4, 2019. It is now read-only.

Process output should be convertable to string #400

Open
ForNeVeR opened this issue Nov 24, 2015 · 2 comments
Open

Process output should be convertable to string #400

ForNeVeR opened this issue Nov 24, 2015 · 2 comments

Comments

@ForNeVeR
Copy link
Contributor

In PowerShell I can do the following:

PS> cmd /c where cmd
C:\Windows\System32\cmd.exe
PS> $(cmd /c where cmd).Split('.')[0]
C:\Windows\System32\cmd

In Pash I cannot:

PASH> whereis ls
ls: /nix/store/5vrf2s2qj8q20vv6wskqkgzdz8h8g4qf-system-path/bin/ls
PASH> $(whereis ls).Split(':')
ls: /nix/store/5vrf2s2qj8q20vv6wskqkgzdz8h8g4qf-system-path/bin/ls
Cannot invoke a method of a NULL expression
  +CategoryInfo: InvalidOperation, Reason: PSInvalidOperationException
  +FullyQualifiedErrorId: InvalidOperation

Note that Pash echoes the command output but does not calls methods on it.

But it works if I place the command output to a variable:

PASH> $x = whereis ls
PASH> $x.Split(':')[1].Trim()
/nix/store/5vrf2s2qj8q20vv6wskqkgzdz8h8g4qf-system-path/bin/ls
@sburnicki
Copy link
Member

I think the problem is that whereis is a local command which by default outputs to the terminal directly and doesn't write the result to pipeline. It does that only in some cases and then there is a WriteSideEffectsToPipeline flag set. This basically happens when the ExecutionVisitor's EvaluateAst method is called.

For simple local program execution this behavior is wanted, as always writing the program's result to a pipeline would result in loss of output colors and formatting, and sometimes even in functionality.

We'd therefore need to identify the cases when and where the flag is set to true or false and make sure that the flag is set if there is a member invocation expression following.

I'm afraid this topic is currently fairly intransparent and related to the discussion in issue #268.

@ForNeVeR
Copy link
Contributor Author

ForNeVeR commented Dec 2, 2015

Yes, I think you're right, that definitely involves this horrible WriteSideEffectsToPipeline flag.

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

No branches or pull requests

2 participants