Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.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-Window命令行界面_Ruby_Windows_Command Line - Fatal编程技术网

Ruby-Window命令行界面

Ruby-Window命令行界面,ruby,windows,command-line,Ruby,Windows,Command Line,更新--我使用Python尝试了完全相同的方法,效果非常好 import os os.system('certutil.exe -v -getkey "614D628A00000000014C" C:/Users/kra/kevin') 有人能解释一下这个问题吗 如果我运行这个ruby代码: require 'open3' stdin, stdout, stderr = Open3.popen3('certutil -v -getkey "614D628A00000000014C" C:/Us

更新--我使用Python尝试了完全相同的方法,效果非常好

import os
os.system('certutil.exe -v -getkey "614D628A00000000014C" C:/Users/kra/kevin')
有人能解释一下这个问题吗

如果我运行这个ruby代码:

require 'open3'
stdin, stdout, stderr = Open3.popen3('certutil -v -getkey "614D628A00000000014C" C:/Users/kra/kevin')            
puts stdout.read
我得到以下错误:

Querying WIN-3CF41NBPT85.demo.com\demo-CA
CommonName: 614D628A00000000014C
CertUtil: -GetKey command FAILED: 0x80092004 (-2146885628)
CertUtil: Cannot find object or property.
但是,如果我直接从命令行运行该命令,它就会工作

C:\Users\kra>certutil -getkey "614D628A00000000014C" C:/Users/kra/kevin
Querying WIN-3CF41NBPT85.cjndemo.com\cjndemo-CA.....................

"WIN-3CF41NBPT85.demo.com\demo-CA"
  Serial Number: 614d628a00000000014c
  Subject: CN=Kevin, C=GB
   NotBefore: 11/30/2012 10:20 AM
   NotAfter: 5/7/2013 9:29 AM
  Template: Copy of Web Server
  Version: 3
  Cert Hash(sha1): 88 b1 7a 74 8c be 73 d5 16 07 7f 19 16 57 14 c5 dd a9 79 7f


Recipient Info[0]:
CMSG_KEY_TRANS_RECIPIENT(1)
CERT_ID_ISSUER_SERIAL_NUMBER(1)
    Serial Number: 129e45d3000000000130
    Issuer: CN=demo-CA, DC=demo, DC=com
    Subject: CN=kra, CN=Users, DC=demo, DC=com
CertUtil: -GetKey command completed successfully.
有趣的是,如果我运行这个ruby代码:-

require 'open3'
stdin, stdout, stderr = Open3.popen3('certutil -recoverkey -p lexicon C:\Users\kra\kevin C:\Users\kra\kevin.pfx')
puts stdout.read
它也起作用

Computed Hash: 6e d3 b8 ad 93 16 7b f0 fb b3 f5 cd 7e e4 bb ad fb 95 a0 81

User Certificate:
    Serial Number: 614d628a00000000014c
    Issuer: CN=demo-CA, DC=demo, DC=com
    Subject: CN=Kevin, C=GB
    Cert Hash(sha1): 88 b1 7a 74 8c be 73 d5 16 07 7f 19 16 57 14 c5 dd a9 79 7f
CertUtil: -RecoverKey command completed successfully.
我假设这是某种奇怪的环境问题,因为ruby显然能够调用certutil.exe命令?

的第一个参数是要传递给子命令的环境。有时,我不得不用它来让事情按我预期的那样运转:

Open3.popen3(ENV, 'command') { ... }
将当前脚本的环境传递给sub命令。当前脚本将从命令行继承其环境,因此,理论上,子命令将具有与在命令行发出的命令相同的信息

如有必要,您还可以提取ENV的子集,或者在调用
popen3
之前临时覆盖变量



尝试使用,而不是
popen3
。这很相似,但我认为它没有那么低。我在
popen3
中看到了一些奇怪的行为
capture3
很好地避免了这些行为。同样,请注意,您可以将
ENV

传递到“-getkey”中,尝试忽略参数中的引号。您的命令shell可能会将它们删除,而Ruby exec(popen3)命令可能不会。是的-尝试了这个。这没什么区别。你试过在Ruby中使用
system(…)
或反引号(
output=%x(…)
)吗?是的,试过,但问题是一样的!所以我尝试了stdin,stdout,stderr=Open3.popen3(ENV,'certutil.exe-v-getkey“614D628A00000000014C”C:/Users/kra/kevin')。但是它似乎没有帮助!好的-刚刚尝试了capture3-不幸的是它没有帮助。与popen3的结果相同。疯狂的事情是,如果我调用上面的python脚本,它就工作了,如果我把字符串放在批处理文件中,它就不工作了!