【问题标题】:access denied when connecting commands连接命令时访问被拒绝
【发布时间】:2021-07-31 14:46:53
【问题描述】:

我想将多个命令连接成一个字符串,但我遇到了问题:

如果我在 CMD 中单独运行以下命令,它可以工作:

powershell.exe
pushd path_to_active_UNC_directory
$Env:PRESTO_PASSWORD=XXXXX 
java -jar presto.jar --server https://address.of.server --catalog hive --debug --schema murex_tradestore --user=test --password --execute "SELECT * FROM TABLE;" --output-format CSV_HEADER > test.csv
popd

但是,如果我连接命令,它只能工作到$Env:PRESTO_PASSWORD=XXXXX

如果我添加java -jar presto.jar --server https://address.of.server --catalog hive --debug --schema murex_tradestore --user=test --password --execute "SELECT * FROM TABLE;" --output-format CSV_HEADER > test.csv,则会出现“拒绝访问”错误

这可能是什么原因?鉴于当我一个接一个地运行命令时它确实有效。在我连接命令时运行的代码下方:

powershell.exe; pushd path_to_active_UNC_directory;$Env:PRESTO_PASSWORD=XXXXX; java -jar presto.jar --server https://address.of.server --catalog hive --debug --schema murex_tradestore --user=test --password --execute "SELECT * FROM TABLE;" --output-format CSV_HEADER > test.csv;popd

【问题讨论】:

  • 我猜为了不拒绝访问,您需要提供密码!
  • 这就是$Env:PRESTO_PASSWORD=XXXXX 的用途。可以设置 PRESTO_PASSWORD 环境变量和密码值来避免提示
  • 我的意思是,您正在定义一个环境变量,然后运行一个不使用它的 java 命令和一个也不使用它的 pop-location 命令!那个密码是干什么用的?
  • 我不确定它是如何工作的。但是,如果我设置$Env:PRESTO_PASSWORD=XXX,当我逐行运行它时,它就会被拾取。 PRESTO_PASSWORD 环境变量是根据文档的方法。 docs.starburst.io/350-e/installation/cli.html
  • 我知道环境变量是如何工作的!我要告诉你的是,从你发布的内容来看,没有任何迹象表明有任何东西在使用该密码,你没有向我们提供足够的信息!为了让我们为您提供帮助,您应该提交代码的minimal reproducible example,并提供足够的信息让我们复制您报告的问题。

标签: java powershell cmd


【解决方案1】:

我通过创建一个 powershell 脚本 (ps1) 并运行该脚本解决了这个问题。这样我就不需要“连接”不同的命令了。

现在它似乎提取了密码。

代码:

powershell.exe; Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass; #path_to_ps1 -path $path -usr_pass $usr_pass -usr_name $usr_name -sql_code $sql_code -file_name $file_name -schema $schema

代码 cl1:

param([string] $path = "C:\",
      [string] $usr_pass = "",
      [string] $usr_name = "",
      [string] $sql_code = "",
      [string] $file_name = "",
      [string] $schema = ""
)

pushd $path
$Env:PRESTO_PASSWORD=$usr_pass
java -jar presto.jar --server https://presto-poc.dap.pl.ing.net --catalog hive --debug --schema $schema --user=$usr_name --password --execute "$sql_code;" --output-format CSV_HEADER > $file_name
popd

【讨论】:

    猜你喜欢
    • 2018-04-30
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    • 2023-02-18
    • 1970-01-01
    • 2020-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多