1

I searched and found only fragments of the answer. I am building tool for distribution across the studio. I have an .exe command line program ( a tool which that converts asset formats ) inlcuded as a resource in my VS project.

Based on another thread, I set the inluded .exe's "Copy To Output Directory" property to "copy if newer"; So that it will be included when others install it.

Now i want to call this executable, with arguments, by passing a string that is a built command line, such as

"C:\path\to\myProgram.exe -inputFilename -outputFilename -options"

the problem: what do I really need for C:\path\to\myProgram.exe ? where is my command line executable going to end up installed on the end user's machine?

or does embedding it as a resource open a new way of calling it(with args)?

Logan Bender
  • 367
  • 1
  • 5
  • 12
  • In general, it has to do with where it will be on the end user machine, but I do not know when it comes to embedded resources +1 – Dan Drews Mar 10 '14 at 21:19
  • Take a look at http://stackoverflow.com/q/798655/299327. However as a general rule, I wouldn't call a program a resource. Why are you trying to do this? – Ryan Gates Mar 10 '14 at 21:21
  • Well it's not an embedded resource if you're setting copy if newer. It's being copied to wherever the assembly is. If you want to know where the assembly is try this http://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in – Conrad Frix Mar 10 '14 at 21:23
  • Or http://stackoverflow.com/questions/1658518/getting-the-absolute-path-of-the-executable-using-c based on what you are doing. Note you are just coppying your exe, and a installer is intalling it. It is not an embedded resource, that's a whole nother ball game – Tony Hopkinson Mar 10 '14 at 21:25
  • [edit ok it's not really embedding] I want the C:\path\to\myProgram.exe to be guaranteed present in a foreknown location so I may call it reliably. If there is a better way, I await enlightenment. – Logan Bender Mar 10 '14 at 21:26
  • You have it in a foreknown location, relative to your executable (see my answer). If you want it somewhere else, just put it there as part of your install process and call it from there. – BradleyDotNET Mar 10 '14 at 21:34

1 Answers1

2

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.

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117