2

我正在尝试使用以下 vim 函数在 Windows 上运行我的 sas,但我总是收到错误消息,说 system 的参数无效。

一些vim专家可以帮助我吗?

myy sas 安装在:

C:\Program Files\SAS\SAS\9.1\sas.exe

function! RunSASonCurrentFile()
    " Make sure this is a SAS program file (ends with .sas) so that
    " we don't run SAS on a log file or similar.
    :let checkSASpgm=match(expand("%"),"\.sas")

    " If we did not match .sas in the file name, end this function with
    " a warning msg
    if checkSASpgm==-1
       :echo "*** Current file is not a SAS program.  SAS run has been canceled."
       :return
    endif

    " Ask user if we want to run SAS so we don't accidentally run it.
    :let l:answer = input("Run SAS? Y/N ") 
    :if (l:answer == "Y" || l:answer == "y")

    " If file has been modified, save it before running
    if exists(&modified)
       :echo "*** Saving modified file before SAS run..."
       :w
    endif

    " Run SAS on path/file name (modify to your location of sas)
    :echo "*** Running SAS..."
    "let returntxt = system("/usr/local/bin/sas -nodms " . shellescape(expand("%:p")))
    " The following may work for your Windows system. Comment the line above and uncomment 
    " the two lines below and make them one long line.
    let returntxt = system("\"" . shellescape("C:\\Program\ Files\\SAS\\SAS\9.1\\sas.exe") 
    ".  "\ -nosplash" . "\ -sysin" . "\ " . shellescape(expand("%:p")) .  "\"") 

    " Shows the return messages from the SAS commandline (may be useful
    " if no log produced)
    :echo "*** SAS commandline: " . returntxt

    :call LoadSASLogList()

    :else
    :echo "SAS Run cancelled."

    " endif for the Run SAS? check
    :endif
  endfunction
4

2 回答 2

4

Vim 补丁 7.3.443 改变了 shell 转义的行为(由于神秘的 Windows shell 转义规则,这仍然是一个问题点)。之前,如果命令行包含带有空格的(本身引用的)可执行文件,则必须将整个命令行括在双引号中,现在必须删除这些。尝试以下操作:

let returntxt = system(shellescape('C:\Program Files\SAS\SAS\9.1\sas.exe') . ' -nosplash -sysin ' . shellescape(expand('%:p')))

这也通过使用单引号字符串避免了一些额外的转义。

于 2013-10-06T11:41:06.257 回答
0

如果那是您的函数的确切文本,我认为您在 SAS 和 9.1 之间缺少第二个 \ let returntxt = system("\"" . shellescape("C:\\Program\ Files\\SAS\\SAS\9.1\\sas.exe")

于 2013-10-06T06:16:28.090 回答