Small problem with GetCommandLine

Started by Roland Stowasser, October 26, 2024, 07:03:01 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Roland Stowasser

Hi Charles,

I stumbled upon a problem with GetCommandLine. I tried to run this little code snippit in a cmd window:

$ filename "TestCommand.exe"
'uses rtl32
'uses rtl64

#Console
% TryAttachConsole

uses Console

char gcl
gcl =  GetCommandLine

printl gcl

printl "Enter..." : wait

When I run TestCommand.exe everything works as expected. But when I try to run:
co2.exe Testcommand.o2bas arg1
then the app will be compiled to arg1.exe, as if I applied co2.exe -c TestCommand.o2bas arg1.exe. Is this done on purpose? Is there another possiblility to get the arguments, if I want to run the app in JIT mode?

Charles Pegge

Hi Roland,

The compiler processes the entire command line for filenames and switches. In your example 'arg1' will be treated as a target filename 'arg1.exe' instead of going into JIT mode. I could add a new switch to allow arguments to be included in JIT execution if you think this might be useful.

Roland Stowasser

Hi Charles,

I noticed this different behavior because I run my apps in JIT mode, as a 32-bit exe and as a 64-bit exe. I also saw that this already worked in JIT mode,
version: 0.1.0 2019-03T20:36:03
This was a while ago, and it is a bad sign to me that I have not noticed this before. But in the meantime you have improved Oxygenbasic so much that other topics have been more interesting.
I would actually prefer the old procedure as this also happens when running the exe file. However, if I am the only one who finds this interesting, then it really does not need to be changed. I now know what is happening. (It took some time until I found out)

Charles Pegge

#3
This is a compiler candidate which includes a -j switch to suppress interpretation of the command line beyond the source filename, and thus invoke JIT execution with a complete command line.

co2.exe -j myFile.o2bas 1 2 3 4

If it is satisfactory I can include it in the next release with its 64bit twin.

Roland Stowasser

Hi Charles,

I added a function of SysUtil.inc in TestCommand.o2bas:

$ filename "TestCommand.exe"
'uses rtl32
'uses rtl64

#Console
% TryAttachConsole

uses Console
uses SysUtil

print "GetCommandLine = "
string gcl
gcl =  (char) GetCommandLine
printl gcl

print "CommandLineArgs = "
string cla
cla = CommandLineArgs()
printl cla
 
printl "Enter..." : wait

With the modified co2.exe, I think I can get all the necessary information about a file's arguments in both JIT mode or as an exe file. Personally, I think this change would not be superfluous.

Charles Pegge

#5
Okay, I've included the -j option in both compilers and posted an updated OxygenBasic. but nothing else has changed, so I have attached both compilers here with the source code.

James C. Fuller

Charles,
   Windows Defender does not like co2.exe

James

Charles Pegge

I have reported it to Microsoft:

co2.exe
Submission ID: 6f9e9c07-f388-41d6-989e-9892a901b6b1
Status: Submitted
Submitted by: c.pegge...
Submitted: Oct 29, 2024 12:55:03
User Opinion: Incorrect detection


James C. Fuller

MS was pretty fast on this one. All is ok now

James

Nicola

A big hello to everyone. 
I wanted to thank Charles for his excellent work. :)

Cheers

Nicola

Hi Charles,
Wanting to include this information in the help, in which section could I place it?

nico

Charles Pegge

Thanks Nicola,

We do not have any specific documentation on the compilers. The option list only appears when co2.exe is executed without params. So I think the information would need to go into a separate chapter, which might also include how to associate o2bas source files with co2.exe or co2m64.exe for JIT (script) file execution direct from the file icon.

Nicola

Great, could you write some notes that I could use beyond what I would get from running co2 in the console?

  compiler options:
  <filename>      compile and execute directly in memory
  -a <filename>    list assembly code
  -b <filename>    list o2 machine script
  -c <filename>    <optional filename>  compile to 32bit binary
  -32 <filename>  <optional filename>  compile to 32bit binary
  -64 <filename>  <optional filename>  compile to 64bit binary
  -i <filename>    list intermediate code
  -m              output to console
  -d              compile to DLL instead of EXE
  -r              run compiled file
  add <filename.res> to link resources

Charles Pegge

It is fairly self-explanatory. I can't think of anything that needs to be added.

  compiler options:
  <filename>       compile and execute directly in memory
  -a <filename>    list assembly code
  -b <filename>    list o2 machine script
  -c <filename>    <optional filename>  compile to 32bit binary
  -32 <filename>   <optional filename>  compile to 32bit binary
  -64 <filename>   <optional filename>  compile to 64bit binary
  -i <filename>    list intermediate code
  -m               output to console
  -d               compile to DLL instead of EXE
  -r               run compiled file
  -j               jit mode arguments follow
  add <filename.res> to link resources