I’m not sure whether this is a Xojo/RealStudio problem or something to do with the Unix executable I’m using, hence posting in ‘off-topic’.
I have a C program which I have compiled into a Unix executable. You can find both at https://dl.dropboxusercontent.com/u/16814562/anagram.zip .
I have compiled it using the incantation
cc -o anagram ./anagram.c
When I run the program in Terminal:
./anagram -v carthorse
I get a lot of words, ending in ‘orchestra’.
When I run the program in RealStudio 2012 v2.1
dim s as shell
s.Execute ("""" + ReplaceAll(SpecialFolder.Desktop.Child("anagram").ShellPath, "\", "") + """ -v carthorse")
I get no words when I inspect s.result - just a bit of logging info saying it couldn’t find any anagrams.
(-v is a ‘verbose’ switch which is useful for showing that it’s tried to do something.)
I’m utterly baffled - I can’t see why it would be doing this. But then I’m also not used to compiling c programs so I wonder if I’ve done something wrong. I wonder if it could be a permissions or path issue, but I can’t see anything which would cause the problem.
Any light which anyone can shed on this would be very gratefully appreciated!
dim s as shell
s.Execute ("""" + ReplaceAll(SpecialFolder.Desktop.Child("anagram").ShellPath, "\", "") + """ -v carthorse")
Strange… Why this “”""""""""" everywhere? If you want to have “” in the Execute String do it with “+chr(34)+” or replace the " with ’
I’ll try it now Give me a second
s.Execute (SpecialFolder.Desktop.Child(“anagram”).ShellPath+"/anagram “+”-v carthorse")
Print s.Result[/code]
when i do it like this i get this results
[quote]9 letters in key.
Building wordlist…
222 suitable words found
Sorting wordlist…
After sorting:
orchestra […][/quote]
(cool little program by the way )
…whereas with exactly that code, copied and pasted from your previous message, in a pushbutton’s Action, replacing ‘Print s.result’ with ‘break’ and inspecting, I get:
[quote]9 letters in key.
Building wordlist…
0 suitable words found
Empty dictionary or no suitable words.[/quote]
Sorry, Jan-Ole, I don’t quite understand - what do you mean by ‘There you go’? When I run the code I’d expect to get the list of words, but instead I get ‘no suitable words’… yet running that same command from Terminal gives me the list as I’d expect…?
I verified that any call to anagram from the shell, even through a bash script, leads to the same result. Even the code posted by Jan-Ole does not generate anything, contrary to what he alleges.
Could it be that the code in anagram is set to prevent process launch by a program instead of the user ?
edit: i missed, that youre using real studio 2012v2.1 sorry… i actually dont have it, so i cant test it.
fyi: in xojo 2014 2 it works for desktop,web and console.
When run from the command line, anagram works fine
When run from a Console program shell in the IDE, works fine
When run from a build of that Console program shell from Terminal, works fine
When a desktop program shell is used to run anagram, it does not work
When the console program shell is run from the desktop program, it does not work
The only conclusion is that somehow, anagram is set to work only from a Terminal command line. I perused the C source for any comment to that effect, but there is no mention of “command line” that could be a hint. And my knowledge of C is rather limited. But I strongly believe the issue is with the C program.
the Shell object runs in a different environment than the Terminal app. To test this out, try running the command ‘env’ and see what you get. This might explain the problem?
Just compared. I was supposing that a shell would have another user name but that was wrong. At first glance environment variables are the same. So the problem must be somewhere else. Maybe under shell anagram does not have the same permissions and cannot use temporary files ?
Thanks so much to everyone for trying this. I don’t know whether I’ve discovered a) a problem in the C program which I and others can’t see; b) a bug in how the Shell works, c) something else, or d) any combination of some or all of the others. I’m highly interested as to what could be going on, but also entirely understand if this isn’t something that people want to be spending time on
Thanks!
Hamish
if (isatty(0)) {
if (freopen("/usr/share/dict/words", "r", stdin) == NULL) {
fprintf(stderr, "%s: cannot open dictionary.\
", progname);
exit(1);
}
}
This tests if the file descriptor in slot 0 (stdin) is attached to a a tty
This would be TRUE in Terminal but NOT in Shell
Change that to
if (1) {
if (freopen("/usr/share/dict/words", "r", stdin) == NULL) {
fprintf(stderr, "%s: cannot open dictionary.\
", progname);
exit(1);
}
}
This makes it so the word list in /usr/share/dict/words gets read regardless of being attached to a tty
Not sure why that matters but thats what makes this not work