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

Stray characters in stdout, stderr #4

Closed
finestructure opened this issue Feb 6, 2017 · 6 comments
Closed

Stray characters in stdout, stderr #4

finestructure opened this issue Feb 6, 2017 · 6 comments

Comments

@finestructure
Copy link
Contributor

When running commands with echo configuration I’m seeing stray characters in the console:

Stdout:
Login Succeeded
X�@Q��
Stderr:

I first noticed this also when reading from RunResults.stdout and trying to parse it. It looks like something is reading past EOF. I once got an entire extra line from another command in the output stream.

@finestructure
Copy link
Contributor Author

I’ve just added a test for this issue, although note that the failure is not visible in the test itself but in the tests console log.

$ swift test
Test Suite 'All tests' started at 2017-02-11 11:35:35.082
Test Suite 'ProcessPackageTests.xctest' started at 2017-02-11 11:35:35.083
Test Suite 'ProcessTests' started at 2017-02-11 11:35:35.083
Test Case '-[ProcessTests.ProcessTests testICanEchoOnlyTheCommand]' started.
Test Case '-[ProcessTests.ProcessTests testICanEchoOnlyTheCommand]' passed (0.001 seconds).
Test Case '-[ProcessTests.ProcessTests testItCanEchoBackNothing]' started.
Test Case '-[ProcessTests.ProcessTests testItCanEchoBackNothing]' passed (0.000 seconds).
Test Case '-[ProcessTests.ProcessTests testItCanEchoBackTheCommandOnly]' started.
Test Case '-[ProcessTests.ProcessTests testItCanEchoBackTheCommandOnly]' passed (0.000 seconds).
Test Case '-[ProcessTests.ProcessTests testItDoesNotEchoIfEmpty]' started.
Test Case '-[ProcessTests.ProcessTests testItDoesNotEchoIfEmpty]' passed (0.000 seconds).
Test Case '-[ProcessTests.ProcessTests testItDryExecutesLS]' started.
Test Case '-[ProcessTests.ProcessTests testItDryExecutesLS]' passed (0.000 seconds).
Test Case '-[ProcessTests.ProcessTests testItEchosBackStdoutAndStderr]' started.
Test Case '-[ProcessTests.ProcessTests testItEchosBackStdoutAndStderr]' passed (0.000 seconds).
Test Case '-[ProcessTests.ProcessTests testItEchosStderrtOnly]' started.
Test Case '-[ProcessTests.ProcessTests testItEchosStderrtOnly]' passed (0.000 seconds).
Test Case '-[ProcessTests.ProcessTests testItEchosStdoOutOnly]' started.
Test Case '-[ProcessTests.ProcessTests testItEchosStdoOutOnly]' passed (0.000 seconds).
Test Case '-[ProcessTests.ProcessTests testItExecuteLS]' started.
Test Case '-[ProcessTests.ProcessTests testItExecuteLS]' passed (0.007 seconds).
Test Case '-[ProcessTests.ProcessTests testItExecutesACommanAndHandlesErrorsdWithDummyExecutor]' started.
Test Case '-[ProcessTests.ProcessTests testItExecutesACommanAndHandlesErrorsdWithDummyExecutor]' passed (0.000 seconds).
Test Case '-[ProcessTests.ProcessTests testItExecutesACommandWithDummyExecutor]' started.
Test Case '-[ProcessTests.ProcessTests testItExecutesACommandWithDummyExecutor]' passed (0.000 seconds).
Test Case '-[ProcessTests.ProcessTests testStrayOutput]' started.
/Users/sas/Projects/GitHub/Process/Tests/ProcessTests/ProcessTests.swift:179: error: -[ProcessTests.ProcessTests testStrayOutput] : XCTAssertEqual failed: ("Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
a���") is not equal to ("Lorem ipsum dolor sit amet,
consectetur adipiscing elit,

") -
Test Case '-[ProcessTests.ProcessTests testStrayOutput]' failed (0.003 seconds).
Test Suite 'ProcessTests' failed at 2017-02-11 11:35:35.096.
         Executed 12 tests, with 1 failure (0 unexpected) in 0.012 (0.013) seconds
Test Suite 'RunTests' started at 2017-02-11 11:35:35.096
Test Case '-[ProcessTests.RunTests testExample]' started.
RunResults(exitStatus: 127, stdout: "", stderr: "/bin/sh: rbenv: command not found\nnchd.3muIAnXsE")
Test Case '-[ProcessTests.RunTests testExample]' passed (0.003 seconds).
Test Suite 'RunTests' passed at 2017-02-11 11:35:35.099.
         Executed 1 test, with 0 failures (0 unexpected) in 0.003 (0.003) seconds
Test Suite 'ProcessPackageTests.xctest' failed at 2017-02-11 11:35:35.099.
         Executed 13 tests, with 1 failure (0 unexpected) in 0.015 (0.016) seconds
Test Suite 'All tests' failed at 2017-02-11 11:35:35.099.
         Executed 13 tests, with 1 failure (0 unexpected) in 0.015 (0.017) seconds

Two things to note:

  • the failure handler picks up stray characters a��
  • there’s an odd line RunResults(exitStatus: 127, stdout: "", stderr: "/bin/sh: rbenv: command not found\nnchd.3muIAnXsE”) in there that only appears when running this test and it’s picking up something from my shell.

@finestructure
Copy link
Contributor Author

The problem I’m having with this is that it’s not possible to reliably parse command output due to these stray characters appearing in the output.

@nsomar
Copy link
Member

nsomar commented Feb 11, 2017

@feinstruktur Thanks so much for the failing test, I think I caught the issue.
The string that I tried to read lacked the null termination, which meant String was not able to figure where to terminate the string.

I am however not able to reproduce the issue on my machine, can you please try to apply the git diff attached here to your branch and see if it fixes it.

fix.diff.zip

Please let me know if this fixes it :)

@finestructure
Copy link
Contributor Author

finestructure commented Feb 12, 2017

Yep, I think that did it and null termination was exactly what this looked like :) I've tried this in my project and I'm not getting the junk anymore.

I still see the stray line RunResults(exitStatus: 127, stdout: "", stderr: "/bin/sh: rbenv: command not found\n") (now without the junk after the \n) in the test result output but that might actually be genuine as a result of the forced test failure?

Thank for the quick fix!

@nsomar
Copy link
Member

nsomar commented Feb 12, 2017

I think that the \n is correct here.

Would you mind opening a PR to fix the issue?
(I could do it but copying the test from your PR looks kinda wrong :D)

@finestructure
Copy link
Contributor Author

finestructure commented Feb 12, 2017 via email

@nsomar nsomar closed this as completed in 55c432b Feb 13, 2017
nsomar added a commit that referenced this issue Feb 13, 2017
Fixes #4 (Stray characters in stdout, stderr)
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