Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从任务调度器运行ruby open网络文件时失败_Ruby_Windows - Fatal编程技术网

从任务调度器运行ruby open网络文件时失败

从任务调度器运行ruby open网络文件时失败,ruby,windows,Ruby,Windows,守则: def log_it log_entry puts log_entry f = File.open("C:/test/test_open_file.log", "a") f.puts log_entry f.close end if File.exist?("C:/test/test_open_file.log") File.delete("C:/test/test_open_file.log") end begin f = File.open("//Serve

守则:

def log_it log_entry
  puts log_entry
  f = File.open("C:/test/test_open_file.log", "a")
  f.puts log_entry
  f.close
end

if File.exist?("C:/test/test_open_file.log")
  File.delete("C:/test/test_open_file.log")
end
begin
  f = File.open("//ServerName/sharename/sample_file.csv", "w")
  puts f.class
rescue Exception => e
  log_it "e.message: #{e.message}\n#{e.backtrace}"
end
当我从cmd.exe窗口运行它时,它运行正常,但如果我从计划任务运行它,它将失败,但有一个例外

e.message: Invalid argument @ rb_sysopen - //ServerName/sharename/sample_file.csv
我已尝试使用我的帐户(管理员帐户)和管理员本身,但这两个帐户都无法在计划的任务中工作。我已选择“无论用户是否登录都运行”,并选中“以最高权限运行”,以及“配置为:”设置为Windows 7,Windows Server 2008 R2。这是一台Windows 7计算机。我将“开始”设置为该脚本所在的目录。最后,我尝试选中“以管理员身份运行”在ruby.exe属性对话框的兼容性选项卡上,没有区别


这显然与实际尝试连接到远程服务器的帐户有关,但是如果我告诉它使用我的帐户,那么当我从命令提示符运行它时,为什么我没有问题?

如果有人有类似的问题,我会添加以下行:

system("net use x: \\\\ServerName\\sharename /user:username password")
和更改文件。打开到

f = File.open("x:/sample_file.csv", "w")
这就成功了。我仍然想知道如何使UNC版本工作,但是,如果有人知道