title: Running VBS script with Ruby
body: <p>Is it possible to run a VBScript from Ruby? I have several scripts to automate some tasks in SAP systems and I'm currently running them from Excel.</p>
  
  <p>I'd like to move this to Ruby, where my other modules are in place. Is this possible, and if so, how can I accomplish this?</p>
  
  <p>EDIT</p>
  
  <p>More background info:</p>
  
  <p>I'm using VBScripts to perform some repetitive daily tasks in certain SAP transactions. I have to carry some data to and from an SAP system. I've integrated the VBScripts to VBA and I run them via Excel where I also parse the data if necessary. I'm passing some variables (users, transactions etc.) to the scripts as well.</p>
  
  <p>Now I need to move this part from the Excel to my Ruby app and trigger these VBScripts there and also collect the returned data and use them in the Ruby app.</p>
  
  <p>@nmiranda: I've gone through a lot of SCN resources (also the one you mentioned), but I can't use ES, because I don't have the appropriate user level for that. The other option is to use the RFC to connect to the system and perform the tasks (<a href="https://github.com/mydoghasworms/nwrfc" rel="nofollow">https://github.com/mydoghasworms/nwrfc</a>) but I haven't had any success yet.</p>
  
  <p>So I thought I'd try to run the VBScripts from Ruby as described above. However, doing it this way would also require me to pass those variables as arguments to the VBScripts.</p>
  
  <p>Example:</p>
  
  <ol>
  <li>Run ruby script and pass the arguments to VBScript</li>
  <li>Run VBScript</li>
  <li>Perform tasks in the system</li>
  <li>Leave the system</li>
  <li>Parse the data received from the system (not always the case)</li>
  </ol>
  
  <p>So far I’ve searched for possibilities to do this but I haven’t found the resources mentioned in the answer below. Also my knowledge on this is very limited, hence I’ve asked here.</p>
  
  <p>Now I’ve tried the suggestion below and it works:)</p>
  
  <pre><code>require 'open3'
    stdin, stdout, stderr = Open3.popen3('cscript my_script.vbs')
  </code></pre>
  
  <p>I call the script above and this performs the tasks in the already open system.</p>
  
  <p>Would this be the optimal way of doing it? And, is it possible to pass in the arguments to the VBScript?</p>
  
  <p>I'm passing the argument like so:</p>
  
  <pre><code>require 'open3'
    stdin, stdout, stderr = Open3.popen3('cscript my_script.vbs 0001')
  </code></pre>
  
  <p>And capturing them like so in my VBScript:</p>
  
  <pre><code>WScript.Arguments(0)
  </code></pre>
  
  <p>Is this the correct way? It seems to be working, I just need confirmation...</p>
  
  <p>regards</p>
  
  <p>seba</p>