Getting Path for Resource in Command Line Tool

How to copy bundle resources for command line tool project in Xcode?

A command-line-tool only consists of an executable. No bundle is created and what you are trying to do is not possible.

You’ll have to place the file in some other place and load it from there.

Get full path of a program in cmd line

very simple just

where myprog.exe

for example

where ping

result:

C:\Windows\System32\PING.EXE

Using an included command line exe in a C# program: what's the path?

Copying to the output folder guarantees that the "resource" will have a relative location to your executable. With the method of copying to the output folder, you can use the following code to get the location of your main executable:

String baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

At which point you can use

Path.Combine(baseDir, "myProgram.exe")

to get the final path. If it is in a "tools" folder, you would have to include that in the second argument (that argument is the relative path to your seperate program). The command line arguments go into the ProcessStartInfo object.

C# find file location of xml resource both in web and command line app

The AppContext.BaseDirectory property is a good fit for this:

Gets the file path of the base directory that the assembly resolver uses to probe for assemblies.

pathForResource returns nil in Mac OS X Console Application — Swift

To use bundles with command line tools you need to make sure you're adding the resource files as part of the build phase. It sounds like you appreciate this, but haven't executed it correctly. The following worked for me in a quick demo app:

  1. Add the resource to your project.

Sample Image


  1. Select the project file in the project navigator.

Sample Image


  1. Add a new copy file phase.

Sample Image


  1. To the phase you added in step 3, add the file from step 1. You do this by clicking the + button (circled), and then navigating to the file in question.

Sample Image


When you build the project, you should now be able to access the file's path using NSBundle.

import Foundation

let bundle = NSBundle.mainBundle()
let path = bundle.pathForResource("numbers", ofType: "txt")

if let p = path {
let string = NSString(contentsOfFile: p,
encoding: NSUTF8StringEncoding,
error: nil)
println(string)
} else {
println("Could not find path")
}

// Output -> Optional(I am the numbers file.)

Insert data in codename one resource file in command line or directly

You can check the XML Team Mode flag in the designer tool and save. Once you do that you will see an XML file and a hierarchy next to it in the res directory. This will be used by the designer tool but is invisible to the build process.

You can use the following in the latest designer tool:

java -jar /path/to/designer_1.jar -sync-xml /path/to/theme.res

This updates the res file from the XML.

Alternatively you can add this to the build.xml so it's automated:

<taskdef name="syncXML" classname="com.codename1.build.client.SyncXMLTask" classpath="CodeNameOneBuildClient.jar"/>

Then use this in some place to regenerate the res file:

<syncXML/>

Using stripe CLI to test webhooks in windows dev machine

You need to cd into the folder where you have stored stripe.exe. In your case that's:

C:\Users\GABRIEL> cd Desktop

Then you simply run stripe commands from there and it'll work. For instance:

C:\Users\GABRIEL\Desktop> stripe --help

OR

C:\Users\GABRIEL\Desktop> stripe login


Related Topics



Leave a reply



Submit