X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-3.3 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_43,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: sourceware.org Date: Thu, 23 Apr 2009 14:42:09 -0700 From: ncokwqc02 AT sneakemail DOT com Subject: RE: detecting program invocation from a symbolic link In-reply-to: <20090423195851.GA29258@ednor.casa.cgf.cx> To: cygwin AT cygwin DOT com Message-ID: <1756-47040@sneakemail.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT References: <14974-38810 AT sneakemail DOT com> <20090423195851 DOT GA29258 AT ednor DOT casa DOT cgf DOT cx> Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com The result is apparently compiler dependent. Here's some simple test code: #include int main(int, const char** argv) { using namespace std; cout << "Hello World, I was called from " << argv[0] << endl; return 0; } I build this code to create an executable named test_sym_link.exe using the MS Visual Studio C++ compiler, the Intel C++ compiler, the Metrowerks Codewarrior C++ compiler, and the g++ compiler that came with Cygwin. Then I create a symbolic link like this from a Cygwin shell $ ln -s test_sym_link.exe new_file which produces the following directory entry $ ls -l new_file lrwxrwxrwx 1 ottusch None 17 Apr 23 13:39 new_file -> test_sym_link.exe as expected. If I run the program as built using any of the compilers other than g++ I get $ ./new_file Hello World, I was called from C:\Documents and Settings\ottusch\test_sym_link.exe which, of course, is also what I get if I run ./test_sym_link Only in the case where the compiler is g++ do I get $ ./new_file Hello World, I was called from ./new_file which is the desired, Unix-like, result. These results were all obtained while working from a Cygwin console. The symbolic link 'new_file' shows up as 'new_file.lnk' in a Windows command prompt shell and I don't know how to execute it directly from the command line. Nice that it works with g++ but I need this to work with the other compilers too. Any suggestions? jjo > -----Original Message----- > From: Christopher Faylor > cgf-use-the-mailinglist-please-at-cygwin.com |cygwin.com| > [mailto:...] > Sent: Thursday, April 23, 2009 12:59 PM > To: > Subject: Re: detecting program invocation from a symbolic link > > On Thu, Apr 23, 2009 at 07:18:40PM -0000, > ncokwqc02 AT sneakemail DOT com wrote: > >I have some C++ code that runs from the command line in a console > >shell. It is designed to behave differently depending on whether it > >was called directly by name or by a differently named symbolic link. > >This is easy to check under Unix because argv[0] contains the name of > >the first command line argument, which is either the > executable name or > >the name of the link. > > > >This doesn't work under Windows, however, because argv[0] always > >contains the name of the program being called whether it is > actually on > >the command line or via a link. > > > >Even symbolic links created using 'ln -s' under Cygwin > behave this way. > >I'm wondering if there is a way around this problem. In other words, > >any way for my C++ program to detect the name of the symbolic link if > >one was used to invoke the executable. > > When a cygwin program B is run from a cygwin program A and cygwin > program B is a symlink to program C, then when C is eventually run its > argv[0] should be "B", like on UNIX. > > None of this works when running B from a non-cygwin program like the > windows command prompt since the windows command prompt doesn't > understand cygwin symlinks. > > So, AFAICT, Cygwin does like UNIX. If you are not seeing > this behavior > we need more details and a simple test case to reproduce the problem. > > -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/