简体   繁体   中英

Fastlane comment out quotes in string

I'm trying to show the iOS device attached to the mac using ruby shell execute.

system_profiler SPUSBDataType | grep -A 11 -w "iPad\|iPhone\|iPad"

in terminal this outputs fine.

how do I properly escape the characters and run this in the ruby console

But when adding the same using a lane of my Fastfile, note the escaping quotes using '\\'. I get an error of non zero exit.

desc "Register a new device"
  lane :register_new_device do
      UI.message("Detected device")
      sh("system_profiler SPUSBDataType | grep -A 11 -w \"iPad\|iPhone\|iPad\"")
      device_name = prompt(text: "Enter the device name: ")
      device_udid = prompt(text: "Enter the device UDID: ")
      device_hash = {}
      device_hash[device_name] = device_udid
      register_devices(devices: device_hash)
      new_devices
  end

error:

[08:23:56]: Exit status of command 'system_profiler SPUSBDataType | grep -A 11 -w "iPad|iPhone|iPad"' was 1 instead of 0.
2018-12-07 08:23:55.602 system_profiler[21056:476660] SPUSBDevice: IOCreatePlugInInterfaceForService failed 0xe00002be

expected output:

2018-12-07 08:27:52.170 system_profiler[21266:479375] SPUSBDevice: IOCreatePlugInInterfaceForService failed xx
        iPhone:

          Product ID: xx
          Vendor ID: xx (Apple Inc.)
          Version: xx
          Serial Number: xxx
          Speed: Up to 480 Mb/sec
          Manufacturer: Apple Inc.
          Location ID: xx / 3
          Current Available (mA): xx
          Current Required (mA): xx
          Extra Operating Current (mA): xx

How can I run the command in the shell and show the output before the user adds the device to Fastlane match?

It seems the command you are running is always returning a status code 1 instead of 0 , even when running it directly. Check by running echo $? after it finished.

If this is indeed the case and expected or wanted, you have to make fastlane's sh accept this. You can do so by giving sh an error_callback parameter that weill be executed if the status is 1. It doesn't actually have to do anything, so an empty method should be fine.

(The internal logic and code behind this is here - note how the error message is output with UI.shell_error! which stops execution when no callback is present, but UI.error which just outputs a red error message when the callback is present.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM