ganado / redtamarin

Automatically exported from code.google.com/p/redtamarin
Other
2 stars 0 forks source link

Running Windows .EXE is incorrectly requiring .EXE to be specified on commandline #43

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If an .EXE for Windows 7 is compiled with redtamarin, it can not be run by 
specifying the executable name without the .exe extension.  If .EXE is 
ommitted, then an avmplus splash screen is displayed, instead of running the 
actionscript.

Most programs can be run under windows dos prompt without specifying the .EXE 
extension.

Example:
> C:\Projects\tamarin\redtamarin>java -jar l/asc.jar -AS3 -import
> l/builtin.abc -import l/toplevel.abc -exe l/redshell.exe sysinfo.as
>
> sysinfo.abc, 914 bytes written
> sysinfo.exe, 957338 bytes written
>
> C:\Projects\tamarin\redtamarin>sysinfo
> You must provide input files, -repl, or -Dselftest, or the executable must
> be a projector file.
> avmplus shell 1.4 release build cyclone
> usage: avmplus
(etc.)

Running with .exe runs the actionscript:

C:\Projects\tamarin\redtamarin>sysinfo.exe
             OperatingSystem.name = Win32
         OperatingSystem.username = Garnet
         OperatingSystem.nodename = ENVY17SPIDER
         OperatingSystem.hostname = Envy17Spider
          OperatingSystem.release = 6.1 build 7601
          OperatingSystem.version = Windows 7 Home Premium Edition Service Pack 1
          OperatingSystem.machine = i686
           OperatingSystem.vendor = Microsoft
       OperatingSystem.vendorName = Windows 7
    OperatingSystem.vendorVersion = 6.1.1
OperatingSystem.vendorDescription = Microsoft Windows 7 Home Premium Edition 
Service Pack 1 (Vienna 6.1 build 7601)

Original issue reported on code.google.com by thegar...@gmail.com on 17 Jul 2011 at 5:02

GoogleCodeExporter commented 9 years ago
so here what happen

when you bundle an *.abc file with a shell.exe you are basically creating a 
projector
when the shell execute it tries to discover if it is in "projector mode" or 
"shell mode"
and here without the ".exe" extension the shell fail to see it is in "projector 
mode"
so it runs the regular shell command (and end up showing the usage informations)

the problem is situated here
http://code.google.com/p/redtamarin/source/browse/trunk/shell/avmshell.cpp#695

apparently running an executable without the ".exe" extension does not fill the 
argv[0] value,
and because argv[0] is NULLL, then the redshell fail to reckonize it is a 
projector

I ll make some tests with something like
{{{
char *Path;
GetModuleFileName(NULL, Path,MAX_PATH); 
printf("%s\n", Path);
}}}

see if it gives better result under Windows

also as an alternative if you run under cygwin there is no issues (eg. argv[0] 
is found)
see the attached screenshot.

Original comment by zwetan on 18 Jul 2011 at 12:51

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by zwetan on 28 Oct 2011 at 1:31

GoogleCodeExporter commented 9 years ago
just gave redtamarin a spin - very nice work.

i've noticed this issue, but i'm not exactly sure why it happens, as the 
windows default shell should always populate argv[0] with the call (being 
"a.exe" or simply "a"); also to my knowledge the value of argc should be >=1 on 
DOS/CMD/NTVDM. on the other hand cygwi/msys with bash/sh should populate it 
with a full path.

> apparently running an executable without the ".exe" extension does not fill 
the
> argv[0] value, and because argv[0] is NULLL, then the redshell fail to 
reckonize
> it is a projector

as mentioned above i cannot confirm this, but mind that the c entry point 
arguments are shell specific and if you decide to port your code to a not so 
common OS, its shell might not even allow arguments (argc = 0, *argv = NULL). 
if you are mainly targeting popular OS, arguments should work on such (thus a 
puzzle for this specific issue).

i haven't compiled your code since there are a bit too much dependencies for 
me: ant, python, jre etc., but here is a simple test with argv[0] / 
GetModuleFileName() for windows:

// -------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define STRIP_PATH(buffer, filename) \
    (filename) = strrchr((buffer), '\\'); \
  if ((filename)) \
    (filename)++; \
  else \
    (filename) = (buffer)

int main(int argc, char *argv[])
{
  const char ext_exe[] = ".exe\0";
  char buffer[MAX_PATH] = {0};
  char *filename;
  short i;

  if (!(*argv))
  {
    GetModuleFileName(NULL, buffer, MAX_PATH);
    STRIP_PATH(buffer, filename);

    printf("no arguments, %d, %s\n", argc, filename);
  }
  else
  {
    strcpy((char *)buffer, argv[0]);

    i = -1;
    while (buffer[++i])
      buffer[i] = tolower(buffer[i]);

    if (!strstr((char *)buffer, ext_exe))
      strcat(buffer, ext_exe);

    STRIP_PATH(buffer, filename);

    printf("has argumens, %d, %s\n", argc, filename);
  }

  return 0;
}
// -------------------------------------------------------------------

lubomir
--

Original comment by neolit123 on 13 Jun 2012 at 12:53

GoogleCodeExporter commented 9 years ago
I will investigate that further with the basic command prompt and cygwin under 
Windows

Original comment by zwetan on 20 Nov 2013 at 5:16