symbolic links, aliases, cls clear
SM Ryan
wyrmwif at tango-sierra-oscar-foxtrot-tango.fake.org
Wed Mar 29 21:36:35 EST 2006
"mp" <mailpitches at email.com> wrote:
# i have a python program which attempts to call 'cls' but fails:
#
# sh: line 1: cls: command not found
#
# i tried creating an alias from cls to clear in .profile, .cshrc, and
# /etc/profile, but none of these options seem to work.
#
# my conclusion is that a python program that is executing does not use
# the shell (because it does not recognize shell aliases). is this
# correct?
Shell command alias or Mac OSX file alias, like a Finder Make Alias?
A file alias is similar to a soft link except it has both path
and device/inode like information so that it can still identify
a renamed file. However aliasses are handled at the toolbox level
instead of the kernel, so that unix only code cannot resolve them.
// readalias - Resolve Finder alias files to the actual
// file, if it can be found. The interface is modelled
// after readlink. If the original is not alias
// or could not be resolved, return 0 and set errno.
// Otherwise return a mallocked string with the
// actual file path; caller must free.
//
// On non-macintosh systems, this always returns an
// error.
#ifdef ALIAS
#include <CoreFoundation/CoreFoundation.h>
#include <ApplicationServices/ApplicationServices.h>
static char *readalias(char *original) {
int ec = 0;
CFStringRef path = 0;
CFStringRef resolvedPath = 0;
CFURLRef url = 0;
CFURLRef resolvedUrl = 0;
FSRef fsRef;
char *s = 0;
if (!(path=CFStringCreateWithCString(NULL,original,kCFStringEncodingUTF8))) {
ec = EFAULT; goto exit;
}
if (!(url=CFURLCreateWithFileSystemPath(NULL,path,kCFURLPOSIXPathStyle,0))) {
ec = EFAULT; goto exit;
}
if (!CFURLGetFSRef(url,&fsRef)) {
ec = ENOENT; goto exit;
}
Boolean targetIsFolder,wasAliased;
if ((ec=FSResolveAliasFile(&fsRef,true,&targetIsFolder,&wasAliased))) {
goto exit;
}
if (!wasAliased) {
ec = EINVAL; goto exit;
}
if (!(resolvedUrl=CFURLCreateFromFSRef(NULL,&fsRef))) {
ec = EFAULT; goto exit;
}
if (!(resolvedPath = CFURLCopyFileSystemPath(resolvedUrl,kCFURLPOSIXPathStyle))) {
ec = EFAULT; goto exit;
}
s = (char*)CFStringGetCStringPtr(resolvedPath,kCFStringEncodingUTF8);
if (s) {
s = strcpy(malloc(strlen(s)+1),s);
}else {
int n = 3*CFStringGetLength(resolvedPath) + 1; s = malloc(n);
if (CFStringGetCString(resolvedPath,s,n,kCFStringEncodingUTF8)) {
s = realloc(s,strlen(s)+1);
}else {
ec = EFAULT; goto exit;
}
}
exit:
if (path) CFRelease(path);
if (resolvedPath) CFRelease(resolvedPath);
if (url) CFRelease(url);
if (resolvedUrl) CFRelease(resolvedUrl);
if (ec) {
if (ec<0) ec = ENOENT;
errno = ec; free(s); s = 0;
}
return s;
}
#else
static char *readalias(char *original) {
errno = EINVAL;
return 0;
}
#endif
--
SM Ryan http://www.rawbw.com/~wyrmwif/
But I do believe in this.
More information about the Python-list
mailing list