bq工具,bat文件|调用时转义字符不起作用 [英] bq tool, bat file | escaping characters not working when CALL

查看:132
本文介绍了bq工具,bat文件|调用时转义字符不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用bq工具,我没有问题用尖号转义>运算符:

Using bq tool I have no problem escaping the > operator with a caret ^:

bq query "SELECT x FROM [presentation_dim.dim_events] WHERE event^>1"

但是,当我通过bat文件调用完全相同的命令时,整个程序崩溃了.

However, when I CALL the exact same command through a bat file whe whole thing breaks down.

call bq query "SELECT x FROM [presentation_dim.dim_events] WHERE event^>1"

我了解call是这里的问题.我无法删除它,因为我需要在它之后运行其他命令(bq extractgsutil cp).我试过改编在Windows批处理文件中转义用户输入的内容,无济于事.

I understand call is the problem here. I can't remove it, since I need to run additional commands after it (bq extract and gsutil cp). I've tried adaptations of what is shown on Escape user input in windows batch file, to no avail.

这是怎么了? 预先感谢.

What's wrong here? Thanks in advance.

推荐答案

我想bq.cmd本身包含这样的内容

I suppose bq.cmd itself contains something like this

set param1=%1
set SQL=%~2
python bigQuery.py --%param1% "%SQL%"

因此,行set SQL=%1需要转义特殊字符.

So the line set SQL=%1 requires escaping the special characters.

但是,当您使用CALL时,批处理解析器有一个转义的附加阶段,但在此之前,它还有一个将所有插入号加倍的阶段!

But when you use CALL, the batch parser has an additional phase of escaping but before it also has a phase of doubling all carets!

因此,您在call bq query "SELECT x FROM [presentation_dim.dim_events] WHERE event^>1"中的字符串将转换为 "SELECT x FROM [presentation_dim.dim_events] WHERE event^^>1"

So your string in call bq query "SELECT x FROM [presentation_dim.dim_events] WHERE event^>1" is converted to "SELECT x FROM [presentation_dim.dim_events] WHERE event^^>1"

我认为没有解决方案,只有插入符号才能解决此问题.

I think there is no solution with only carets to solve this problem.

但是您可以通过简单地定义一个包含一个插入符号的变量来避免这种情况

But you can avoid this by simply defining a variable containing one caret

set "caret=^"
call bq query "SELECT x FROM [presentation_dim.dim_events] WHERE event%%CARET%%>1"

这篇关于bq工具,bat文件|调用时转义字符不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆