Ruby IO.popen Permission Denied

288 Views Asked by At

I am very close to getting the Microchip MPLABX MDB (debugger) working with an automated test suite called ceedling. I have a ruby file called sim_test_fixture.rb

This file is to open the mdb.bat and pass it a config file called sim_instructions.txt. When I run the ruby file I am given a permission denied error. Why is that?

The script runs the command "C:\Program Files (x86)\Microchip\MPLABX\v5.05\mplab_platform\bin\"mdb.bat C:\Users\MichaelMi\Documents\SourceTree\LED-Lighting-Driver\test\simulation\sim_instructions.txt When I run the command myself it works just fine. Only when I try to run it from the following ruby file does it fail.

require 'rbconfig'
is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)

OUT_FILE = "./test/simulation/out.txt"
File.delete OUT_FILE if File.exists? OUT_FILE
path = '"C:\Program Files (x86)\Microchip\MPLABX\v5.05\mplab_platform\bin\"mdb.bat C:\Users\MichaelMi\Documents\SourceTree\LED-Lighting-Driver\test\simulation\sim_instructions.txt'
var = IO.popen(path)
Process.wait
if File.exists? OUT_FILE
    file_contents = File.read OUT_FILE
    file_contents.gsub!("\n", "")
    print file_contents
end 
1

There are 1 best solutions below

0
On

I am not 100% sure of the difference but this code works!

require 'rbconfig'
is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
OUT_FILE = "./test/simulation/out.txt"
File.delete OUT_FILE if File.exists? OUT_FILE
if is_windows
    path = '"C:\\Program Files (x86)\\Microchip\\MPLABX\\v5.05"'
    var = IO.popen(path + "\\mplab_platform\\bin\\mdb.bat ./test/simulation/sim_instructions.txt > " + OUT_FILE)
else
    var = IO.popen("#{ENV['MPLABX_ROOT']}mplab_ide/bin/mdb.sh ./test/simulation/sim_instructions.txt > " + OUT_FILE)
end
Process.wait
if File.exists? OUT_FILE
    file_contents = File.read OUT_FILE
    print file_contents
end