连接命令时拒绝访问

时间:2021-05-10 07:23:03

标签: java powershell cmd

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

如果我在 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

1 个答案:

答案 0 :(得分:-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