- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要使用 WScript.Shell 从 VBA 调用脚本 (R)。文件路径包含空格。此外,一系列参数被传递给脚本,其中几个还包含空格。
我已经在路径、参数甚至整个字符串(特别是 this here)周围尝试了所有可以想到的引号和双引号组合。当需要传递参数时,似乎没有任何效果(我在命令行中得到“C:\Program”未被识别”或“无效语法”错误)。
Option Explicit
Private Const QUOTE As String = """"
Sub test()
Dim WS_Shell As Object
Set WS_Shell = VBA.CreateObject("WScript.Shell")
Dim err_code As Long
Dim path As String
Dim arg_1 As String
Dim arg_2_with_spaces As String
Dim complete_cmd_str As String
path = "C:\Program Files\R\R-3.3.2\bin\Rscript.exe"
arg_1 = "F:\path\to\my\script.R"
arg_2_with_spaces = "A string-arg with spaces"
complete_cmd_str = "cmd.exe /K " & QUOTE & path & QUOTE & " " _
& QUOTE & arg_1 & QUOTE & " " _
& QUOTE & arg_2_with_spaces & QUOTE
Debug.Print complete_cmd_str
err_code = WS_Shell.Run(complete_cmd_str, vbMinimizedNoFocus, True)
End Sub
所有这一切都发生在 Windows 7 上。
如何在路径和要传递的参数中运行带空格的命令行脚本?非常感谢任何帮助!
如果从命令字符串中删除前缀“cmd.exe/K”,则代码有效。但是,为了测试和调试,我想在脚本运行后让 shell 窗口保持打开状态。如何实现?
最佳答案
我曾经运行脚本并从 Excel 传递参数,这段代码对我有用。
为了运行脚本非常重要,首先指定 Rscript.exe 的路径和 R 脚本(.r 文件)的路径,然后您可以使用空格传递参数。
Sub run_R()
Dim shell As Object
Set shell = VBA.CreateObject("WScript.Shell")
Dim waitTillComplete As Boolean: waitTillComplete = True
Dim style As Integer: style = 1
Dim errorcode As Integer
Dim path As String
path = Chr(34) & "C:\R\R-3.4.0\bin\i386\Rscript.exe" & Chr(34) & " " & Chr(34) & "C:\Users\userexample\Desktop\accionable.r" & Chr(34) & " " & Chr(34) & "Argument 1" & Chr(34)
errorcode = shell.Run(path, style, waitTillComplete)
End Sub
读取参数的R代码:
args = commandArgs(trailingOnly = T)
cat(args[1])
关于vba - WScript.Shell 运行一个脚本,路径中有空格,参数来自 VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49652606/
我正在使用 Waf 构建一个项目。它有几个第三方依赖项,我想从我的主要 wscript 构建每个依赖项。我的项目是这样组织的: /boost/ /gtest/ /source/ /waf /wscri
我在 Javascript 中使用 ActiveXObject。 var shell = new ActiveXObject("WScript.Shell"); exec = shell.exec('
我正在使用Excel将一些文件上传到带有WinSCP的服务器上。此示例起作用:。现在,我希望Excel等到外壳关闭。。使用来自等待外壳命令完成的信息,我将其组合成以下代码:。不幸的是,这并不管用。Ex
特殊文件夹名称用于索引该集合以检索所需的特殊文件夹,文档中列出了下面的特殊文件夹: AllUsersDesktop AllUsersStartMenu AllUsersPrograms AllUs
我不了解VBScript,但是最近我需要编写一个具有SendKeys功能的脚本,而我无法在批处理文件中做到这一点。当我使用命令cscript test.vbs在Windows 7计算机中从命令提示符运
最近我在一个test.bat中看到这样的代码: @if (@This==@IsBatch) @then @echo off rem This is batch wscript //E:JScript
我正在尝试在本地运行一个 Javascript 文件,它应该使用 ImageMagick 创建一个 CSS 图像 Sprite 。它是 OpenID 选择器 JS 组件的一部分:http://code
我想使用 Windows 脚本宿主(wscript.exe 或 cscript.exe)执行由我的应用程序生成的简单 VBScript/JScript,而不生成临时脚本文件。 我没有找到从标准输入流读
1、wscript对象 描述:提供对 Windows 脚本宿主对象模型根对象的访问。 详述:WScript 对象是 Windows 脚本宿主对象模型层次结构的根对象。它可在任何脚本文件中使用,不
在windows2000下,IIS默认设置是可以web和可执行程序通信的。但是在2003下IIS关于这方面的服务是禁止的。 我现在遇到的问题是,利用web和一个带参数的可执行程序连接。并运行这个带
我试图检查注册表项是否存在,无论我尝试什么,我总是收到错误消息“无法打开注册表项进行读取” 我使用的代码: keyPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\BOS\\
我正在尝试编写一个VBScript,它将以文本文件或csv的形式列出系统上所有已安装的应用程序。我能够找到一个列出所有软件的现有代码(包括名称,版本,日期和大小)。当我当前运行它时,我发现它随着主机回
我正在使用 WScript通过使用 WScript.Shell 调用外部程序来自动化一些任务。 但是,现在它不会等待外部程序完成,而是继续前进。这会导致问题,因为我有一些任务依赖于其他人先完成。 我使
所以我试图通过嵌入在powershell脚本中的cscript.exe运行VBscript。它会因允许错误而不断出错。在调试代码时,我意识到确切的命令不会在cscript或wscript中运行,而是从
嗨,我刚刚发现了 Wscript,我尝试运行一个在浏览器上运行的脚本,但出现了上述错误,我明白问题是什么,但我想问是否有一种方法可以定义文档对象(html 文件和 cookies)可能来自命令提示符,
目前,WScript 在出现脚本错误时会弹出消息框。这些脚本由其他进程调用,并在服务器上运行,因此没有人可以忽略错误框。 我想要的是将错误消息转储到 STDOUT,并执行以返回调用进程。作为 MSGB
我正在运行 Word 2013 中的 VBA 宏。我正在尝试运行需要文件名参数/参数的可执行文件。例如,c:\myfilefilter.exe filetobefiltered.htm 我想使用She
我希望使用 Javascript 执行以下操作,这是我的完整 JS 文件 (test.js): var xo = WScript.CreateObject("Msxml2.XMLHTTP"); var
如果我在 IE9 (win7) 中尝试它,那么它工作得很好,但是当我尝试在 IE8、7、6 (winXP) 中运行这段代码时,调试器写道,它无法创建对象。 var wscript = new Acti
我正在使用此代码:通过单击浏览器中的按钮来创建新文件夹, function exer() { var wsr = WScript.CreateObject("WScript.Shell");
我是一名优秀的程序员,十分优秀!