System ' cmd ' -call to run aws-s3 cli commands ends with error 127

Hi!

Since I found no way to use aws-sdk gems within a SketchUp -extention I tried to find a workaround.

My task:
From the model-data I need to generate .json files and sync/upload them to an aws s3 bucket.

Since there is a problem in using the aws-sdk-s3 gems and uploading the files by ruby-code I tried a workaround: generate the files as .json-files and upload the files with aws cli.

On Windows I create a temp-file, store a generated aws cli command within the textfile, save it as .*vbs script and run the script:

my working code on windows:

  file = Tempfile.new(%w[cmd .vbs])
  file.write("Set WshShell = CreateObject(\"WScript.Shell\")\n")
  file.write("WshShell.Run \"#{cmd.gsub('"', '""')}\", 0\n")
  file.close

  fileuri = URI.encode("file://#{file.path}")
  UI.openURL(fileuri)

On MacOS I tried a similar approach but this only works just to a limited extent on the Mac.

I tried several things and ended up like this:

  file = Tempfile.new(%w[cmd .sh])
  file.write("#!/bin/bash\n")
  file.write(cmd + "\n")
  file.close

  unless system "chmod", "755", file.path
    UI.messagebox($?.to_s)
  end

  unless system "/bin/bash", "-c", file.path
    UI.messagebox($?.to_s)
  end

This approach is working fine ‘within the debug mode’ of SketchUp:

open terminal on MacOS and run:

/Applications/SketchUp\ 2024/SketchUp.app/Contents/MacOS/SketchUp -rdebug “ide port=17001”

I receive debug output within the terminal window. My bash script is called and is working (result of system command is ‘0’). .json files are being uploaded to aws s3.

But as a ‘normal run’ - when I just click in the SketchUp Icon and run SketchUp the system command of ‘system “/bin/bash”, file.path’ results in error ‘127’.

 UI.messagebox($?.to_s)
pid ##### exit 127

Since “chmod” is working I would guess that there is no problem regarding user rights on the file system…

I would be very happy to receive any tips.

Thanks,
Dirk

Please quote code correctly on the forum:

EDIT: Thanx

You don’t need a temporary VBS file to run a command on Windows.
Instead use the Windows Scripting Host via Ruby’s WIN32OLE class:

def run_cmd(cmd)
  require 'win32ole' unless defined?(WIN32OLE)
  WIN32OLE.new("WScript.Shell").Run(cmd.gsub('”', '“”'), 0)
end

… although I do not understand what your are doing with gsub and the smartquote characters.

Hi Dan!

Thanks für your response. I updated the quotes - hope it is correct now.

I tested a lot and took this code block from another post. The Windows part is working!

I tried to get a solution on MacOS - it works while in debug mode (SketchUp startet from a terminal window). But I can’t get it working while started normal from a click on the app icon.

Due to error “127” I made a lot of research regarding inaccessible folders or files.

  • I copied the generated json-files from a sub-user folder to a temp folder
  • I created a temp folder, copied all json files and tried chmod 666, chmod a+r, chmod 777 on this temp folder and/or the included .json files…

I found no way to call system ‘aws s3 sync’ on these files / folders without error 127.

Thanks,
Dirk