[英]How can I pass an escaped javascript string as an argument into windows command line?
I'm attempting to pass an argument to casperJS via command line. 我试图通过命令行将参数传递给casperJS。 I'm executing something like 我正在执行类似
> casperjs ..\test.js " \' { function ( var ) \' asdf"
This is loading the argument as multiple arguments 这正在将参数加载为多个参数
casper.cli.args[0] == "\'"
casper.cli.args[1] == "{"
casper.cli.args[2] == "function"
casper.cli.args[3] == "("
...
Notice it's a new arg everytime there's a space character - The double quotes I placed around the argument obviously don't work with the space character. 请注意,每当有空格字符时,这都是一个新的arg-我在参数周围加上双引号显然不适用于空格字符。
When I concat and print the arguments out I get 当我合并并打印出参数时,我得到
"\'{function(var)\'asdf"
Notice spaces all removed/truncated/whatever. 请注意,所有删除/截断/任何内容的空格。
How can I escape my string so that my js app gets the actual string in 1 argument without dropping content? 我该如何转义我的字符串,以便我的js应用在1个参数中获取实际的字符串而不丢弃内容?
Keep in mine that I need to also keep the escape integrity of the JS string I'm passing as it needs to be interpreted downstream. 请记住,我还需要保持传递的JS字符串的转义完整性,因为它需要在下游进行解释。
I don't really understand what you want to do, if you want to get back a custom argument in your file : 如果您想在文件中返回一个自定义参数,我不太理解您想做什么:
Considering your command is : casperjs test yourFile.js --customArgument=" \\' { function ( var ) \\' asdf"
考虑您的命令是: casperjs test yourFile.js --customArgument=" \\' { function ( var ) \\' asdf"
You get back the content in your file like that : var customArg = casper.cli.get('customArgument');
您可以像这样获取文件中的内容: var customArg = casper.cli.get('customArgument');
This is not what you want? 这不是你想要的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.