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

try to writing to no exit pipe #77

Closed
betsu opened this issue Nov 23, 2018 · 11 comments
Closed

try to writing to no exit pipe #77

betsu opened this issue Nov 23, 2018 · 11 comments
Labels

Comments

@betsu
Copy link

betsu commented Nov 23, 2018

Thanks for fixed #76 .
I use v5.1.1 and run the same pipe code

onchange -v \"**/*/*.scss\" \"**/*/*.css\" -o \"> task/css.txt\" -- echo {{changed}}

css.txt still no content and I get those message

> onchange -v "**/*/*.scss" "**/*/*.css" -o "> task/css.txt" -- echo {{changed}}

onchange: watching **/*/*.scss, **/*/*.css
onchange: "mobile\test\css\style-edit.css" -> change
onchange: executing outpipe "E:\Program Files\nodejs\node.exe E:\Snow.Huang\project\dev\CampaignBuildTool\node_modules\onchange\echo.js > task/css.txt"
onchange: executing command "echo mobile\test\css\style-edit.css"
onchange: "mobile\test\css\style-edit.css" -> change
'E:\Program' ���O�����Υ~���R�O�B�i���檺�{���Χ妸�ɡC
onchange: outpipe completed with 1
程序嘗試寫入到一個不存在的管道。(try to writing to no exit pipe)
onchange: command completed with 0

after I try running this code

onchange -v \"**/*/*.scss\" \"**/*/*.css\" -o \"echo {{changed}} > task/css.txt\"

css.txt is witted and exit code looks fine!

> onchange -v "**/*/*.scss" "**/*/*.css" -o "echo {{changed}} > task/css.txt"

onchange: watching **/*/*.scss, **/*/*.css
onchange: "mobile\test\css\style-edit.css" -> change
onchange: executing outpipe "echo mobile\test\css\style-edit.css > task/css.txt"
onchange: outpipe completed with 0

what's happen in first code?

@betsu betsu changed the title outpipe try to writing to no exit pipe Nov 23, 2018
@blakeembrey
Copy link
Collaborator

@betsu So I couldn't see any difference between this v5 and v4 code paths here and I wasn't able to replicate your problem, but I've pushed out 5.1.2 to experiment with what might be the issue here by fixing the end of stdout and stderr writes. Can you let me know if it makes a difference? Also, did this work for you on v4?

@betsu
Copy link
Author

betsu commented Nov 26, 2018

Hi @blakeembrey,
v4 have same problem and message for me.
5.1.2 it's work fine! but still have one problem:
I use win10. when ${process.execPath} has space in string that make error for me.

onchange: watching **/*/*.{scss,css}
onchange: "css\style-edit.css" -> change
onchange: executing outpipe "E:\Program Files\nodejs\node.exe E:\Snow.Huang\project\dev\CampaignBuildTool\node_modules\onchange\echo.js > task/css.txt"
onchange: executing command "echo css\style-edit.css"
'E:\Program' ���O�����Υ~���R�O�B�i���檺�{���Χ妸�ɡC
onchange: outpipe completed with 1
onchange: command completed with 0

try to writing to no exit pipe looks fixed! then I try to fixed ${process.execPath} problem with add double quotes

const ECHO_CMD = `${process.execPath} ${resolve(__dirname, 'echo.js')}
to
const ECHO_CMD = `\"${process.execPath}\" ${resolve(__dirname, 'echo.js')}

and running.

> onchange -v --await-write-finish -o "> task/css.txt" "**/*/*.{scss,css}" -e "**/*/{style,style-source}.css" -- echo {{changed}}

onchange: watching **/*/*.{scss,css}
onchange: "css\style-edit.css" -> change
onchange: executing outpipe ""E:\Program Files\nodejs\node.exe" E:\Snow.Huang\project\dev\CampaignBuildTool\node_modules\onchange\echo.js > task/css.txt"
onchange: executing command "echo css\style-edit.css"
onchange: command completed with 0
onchange: outpipe completed with 0

Oh! success!!

P.S. In line 68
childOutpipe.stdin.end() maybe change to this.childOutpipe.stdin.end()

@blakeembrey
Copy link
Collaborator

@betsu Thanks! That makes sense. Looks like an escaping issue, I'll look into how to better fix that.

@blakeembrey
Copy link
Collaborator

blakeembrey commented Nov 26, 2018

@betsu Can you take a look at #78?

I settled using single quotes with https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings. I first went with https://github.com/substack/node-shell-quote but saw https://github.com/substack/node-shell-quote/pull/34, don't use Windows so I'm not sure about whether you can escape backslashes there? I saw in your example above you didn't need to escape the backslashes so that may be incompatible with Unix.

@betsu
Copy link
Author

betsu commented Nov 26, 2018

@blakeembrey I have already tested at #78, there's no need to escape the backslashes when add double quotes.
Hope it'll help you.

@blakeembrey
Copy link
Collaborator

@betsu Just to double check, sorry, #78 is using single quotes. Is that still ok? I'm going to merge and release today.

The reason I chose to use single quotes is that it appeared to have a lot less escaping requirements. With double quotes, a lot of interpolation is still possible if you don't escape everything.

@betsu
Copy link
Author

betsu commented Nov 27, 2018

@blakeembrey
I'm sorry for too late to reply, single quotes in windows still have error massage

onchange -v --await-write-finish -o "> task/css.txt && node task/csscompiled.js" "**/*/*.{scss,css}" -e "**/css/{style,style-source}.css" -- echo {{changed}}

onchange: watching **/*/*.{scss,css}
onchange: "css\style-edit.css" -> change
onchange: executing outpipe "'E:\Program Files\nodejs\node.exe' 'E:\Snow.Huang\project\dev\CampaignBuildTool\node_modules\onchange\echo.js' > task/css.txt && node task/csscompiled.js"
onchange: executing command "echo css\style-edit.css"
�ɮצW�١B�ؿ��W�٩κϺаϼ��һy�k���~�C
onchange: outpipe completed with 1
onchange: command completed with 0

I don't know what's better solution, maybe detecting window then add double quote?

@blakeembrey
Copy link
Collaborator

@betsu Hmm, I don't really understand Windows shell scripting. I've been trying to read things like https://blogs.technet.microsoft.com/heyscriptingguy/2015/06/20/weekend-scripter-understanding-quotation-marks-in-powershell/ which seems like it should work. Can you describe the shell you're using on Windows? How do I open it? Maybe I can play around and test in Windows this week.

The issue with using double quotes is we don't want something else (e.g. $foo) to be expanded accidentally in the path. Otherwise, if you can confirm that escaping with backslashes works, we can do that. E.g., does this command work for you:

"E:\\Program Files\\nodejs\\node.exe" E:\\Snow.Huang\\project\\dev\\CampaignBuildTool\\node_modules\\onchange\\echo.js > task/css.txt

(Note the double backslashes which need to normally be escaped in Unix shell's because it's an escape character).

As for detecting windows, I'm not sure how that would work with things like bash on windows (now that it's native).

@betsu
Copy link
Author

betsu commented Nov 27, 2018

@blakeembrey I understand you worried about double quote's problem. But this issue (path with space) that seems like only double quote can be solved on windows. In node exec document https://nodejs.org/dist/latest-v10.x/docs/api/child_process.html#child_process_child_process_exec_command_options_callback written

exec('"/path/to/test file/test.sh" arg1 arg2');
Double quotes are used so that the space in the path is not interpreted as
multiple arguments

Above demo code via index.js work fine!

I'm using vscode terminal that inside are command prompt and powershell.
If you on windows want to use those click tool bar search icon then input cmd or powershell will see that.

@blakeembrey
Copy link
Collaborator

@betsu Sorry for the delay. Releasing #82 now, let me know if it works (I was concerned about the use of backslashes on Windows still).

@betsu
Copy link
Author

betsu commented Dec 12, 2018

@blakeembrey Sorry I'm late. I already tested that is working fine!
Thanks for release 😃

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

No branches or pull requests

2 participants