【问题标题】:do 2012,2016 gce windows servers come with curl already installed?2012,2016 gce windows 服务器是否已经安装了 curl?
【发布时间】:2020-04-18 18:54:18
【问题描述】:

我正在使用节点 js 和 google 的 https://googleapis.dev/nodejs 来启动服务器并运行启动脚本 curl "http://eve-robotics.com/release/EveAIO_setup.exe" --output Eve.exe 在日志中它说 2019/12/29 20:27:44 windows-startup-script-bat: 'curl' 不被识别为内部或外部命令, 这只发生在2012,2016 实例在 2019 上工作正常,如果我不能对这些实例使用此命令,是否有另一种方法可以从启动脚本下载此文件?

更新 这是我为启动脚本运行的命令 Invoke-WebRequest -Uri "http://eve-robotics.com/release/EveAIO_setup.exe" -Headers @{"Upgrade-Insecure-Requests"="1"; "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"; "Accept"="text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9"; "Accept-Encoding"="gzip, deflate"; "Accept-Language"="en-US,en;q=0.9";} -OutFile plz.exe 完成运行后,正如我在实例日志中看到的那样,我连接到它,当我尝试运行 plz.exe 时出现的错误是“系统找不到指定的文件”。

更新现在我在传递完整路径后收到此错误

2019/12/30 21:36:20 windows-startup-script-ps1: Invoke-WebRequest : 路径中的非法字符。 2019/12/30 21:36:20 windows-startup-script-ps1: 在 C:\Windows\TEMP\metadata-scripts903292515\windows-startup-script-ps1.ps1:1 2019/12/30 21:36:20 windows-startup-script-ps1: char:1 2019/12/30 21:36:20 windows-startup-script-ps1: + Invoke-WebRequest -Uri "http://eve-robotics.com/release/EveAIO_setup. ... 2019/12/30 21:36:21 windows-startup-script-ps1: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2019/12/30 21:36:21 windows-startup-script-ps1: + CategoryInfo : NotSpecified: (:) [Invoke-WebRequest], ArgumentE 2019/12/30 21:36:21 windows-startup-script-ps1: xception 2019/12/30 21:36:21 windows-startup-script-ps1: + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Co 2019/12/30 21:36:21 windows-startup-script-ps1: mmands.InvokeWebRequestCommand

这是我正在使用的命令

Invoke-WebRequest -Uri "http://eve-robotics.com/release/EveAIO_setup.exe" -Headers @{"Upgrade-Insecure-Requests"="1"; "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"; "Accept"="text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9"; "Accept-Encoding"="gzip, deflate"; "Accept-Language"="en-US,en;q=0.9";} -OutFile C:\Users\browardboybrian\Desktop\plz.exe

【问题讨论】:

  • 不要使用curl,而是使用PowerShell Invoke-WebRequest
  • 我试过了,但它不是说当我使用 -OutFile Eve.exe 时找不到指定的文件
  • 你想下载 Eve exe 文件到启动 VM 的文件夹中并执行它吗?就这样吗?
  • 您用于Invoke-WebRequest 的确切行是什么?确切的错误信息是什么?将此信息添加到您的问题中。
  • 如果您从启动脚本执行程序,您应该使用完整路径名。您正在使用相对路径。对于 powershell 命令,为什么要添加所有这些标头?这不是你的问题,但这不是必需的。除非 Invoke-WebRequest 报告错误,否则您的问题是您没有指定下载和程序启动的完整路径。

标签: node.js google-cloud-platform google-compute-engine


【解决方案1】:

如果您已经在运行节点服务器脚本,服务器可以通过 http 获取文件并将其保存为 Eve.exe

这是来自Using Node.js to download files的示例

// Dependencies
var fs = require('fs');
var url = require('url');
var http = require('http');
var exec = require('child_process').exec;

// App variables
var file_url = 'http://upload.wikimedia.org/wikipedia/commons/4/4f/Big%26Small_edit_1.jpg';
var DOWNLOAD_DIR = './downloads/';

// We will be downloading the files to a directory, so make sure it's there
// This step is not required if you have manually created the directory
var mkdir = 'mkdir -p ' + DOWNLOAD_DIR;
var child = exec(mkdir, function(err, stdout, stderr) {
  if (err) throw err;
  else download_file_httpget(file_url);
});

// Function for downloading file using HTTP.get
var download_file_httpget = function(file_url) {
  var options = {
    host: url.parse(file_url).host,
    port: 80,
    path: url.parse(file_url).pathname
  };

  var file_name = url.parse(file_url).pathname.split('/').pop();
  var file = fs.createWriteStream(DOWNLOAD_DIR + file_name);

  http.get(options, function(res) {
    res.on('data', function(data) {
      file.write(data);
    }).on('end', function() {
      file.end();
      console.log(file_name + ' downloaded to ' + DOWNLOAD_DIR);
    });
  });
};

【讨论】:

  • 他是用node启动机器,不是在机器上运行。
猜你喜欢
  • 2011-03-02
  • 2011-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-14
相关资源
最近更新 更多