简体   繁体   English

如何将转义的javascript字符串作为参数传递给Windows命令行?

[英]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.

相关问题 如何从命令行将参数传递给我的 Javascript 代码? - How can I pass an argument into my Javascript code from command line? 如何使用 Javascript 在终端命令行中传递 arguments? - How can I pass arguments in the terminal command line using Javascript? 如何使用 npm 在命令行中传递参数并在反应 javascript 代码中读取它 - How to pass argument in command line with npm and read it in react javascript code 我可以将字符串参数传递给 onclick javascript function 吗? - Can I pass a string argument to an onclick javascript function? 如何在NodeJS中传递命令行参数? - How to Pass a Command Line Argument in NodeJS? 如何将命令行参数传递给嵌套脚本? - How to pass a command line argument to a nested script? 是否可以在命令行参数中将字符串变量作为文件传递? - Is it possible to pass a string variable as a file in command line argument? JavaScript:如何将字符串参数传递给函数以用于按该字符串参数的值对对象数组进行排序? - JavaScript: How do I pass a string argument to a function to use to sort an array of objects by the value of that string argument? 如何将PHP数组作为参数传递给JavaScript函数 - How can I pass a PHP array as an argument to a JavaScript function 我如何在javascript中将参数传递出循环 - How I can pass argument out of the loop in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM