Bug 31045 - Incorrect Working Directory Set When Launched From Another Process
Summary: Incorrect Working Directory Set When Launched From Another Process
Status: RESOLVED ANSWERED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Other ()
Version: 2.0.0
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Chris Hamons
URL:
Depends on:
Blocks:
 
Reported: 2015-06-11 20:44 UTC by Jimmy [MSFT]
Modified: 2015-06-12 10:32 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
repro project (60.37 KB, application/zip)
2015-06-11 20:44 UTC, Jimmy [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Jimmy [MSFT] 2015-06-11 20:44:46 UTC
Created attachment 11579 [details]
repro project

*** Overview ***
When a Xamarin.Mac app is launched, its working directory is set to:

> “[app bundle].app/Contents/Resources”

This happens even when the app is launched by another program because the app does not adopt the parent process’ working directory. For example, if “myapp” is launched from the terminal and is supposed to list the files in the working directory:

> $ cd /Users/jimmy/projects
> $ myapp ls

it does not function properly because “myapp” thinks its working directory is “[app bundle].app/Contents/Resources”.


*** Reproduction ***
1. Open and run the attached repro project in XS
2. The current directory is printed in the application output


*** Environment Info ***
=== Xamarin Studio ===

Version 5.9.3 (build 1)
Installation UUID: 94ce5106-6a72-4691-b34e-cd5857b1db66
Runtime:
	Mono 4.0.1 ((detached/ed1d3ec)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010044

=== Apple Developer Tools ===

Xcode 6.3.2 (7718)
Build 6D2105

=== Xamarin.iOS ===

Version: 8.10.1.64 (Business Edition)
Hash: e6ebd18
Branch: master
Build date: 2015-05-21 21:55:09-0400

=== Xamarin.Android ===

Version: 5.1.3.1 (Business Edition)
Android SDK: /Users/jimmygarrido/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.1.64 (Business Edition)

=== Build Information ===

Release ID: 509030001
Git revision: 5a524e1726ed103fdd4fe37e0356f2b35466ce9d
Build date: 2015-06-02 16:35:08-04
Xamarin addins: 51957cfbd06be911b212671ad05c2c6221ac90f9

=== Operating System ===

Mac OS X 10.10.3
Darwin Jimmys-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 1 Chris Hamons 2015-06-12 10:32:58 UTC
The current directory is not something that is safe to depend on. If you build an Xcode executable and launch it's bundle, you can see that it's current directory is not always consistent as well. This is due to how Apple infrastructure, not us. It can also easily be changed by called some 3rd party libraries. Global mutable state.

If you have one program launch another, and want to reference something in the first program's path, you can look into passing the path as an environmental variable or such (have not tried). If you want the location of files inside your own bundle, http://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in or the NSBundle API is what you need.