Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Roland Stowasser on October 26, 2024, 07:03:01 AM

Title: Small problem with GetCommandLine
Post by: Roland Stowasser on October 26, 2024, 07:03:01 AM
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?
Title: Re: Small problem with GetCommandLine
Post by: Charles Pegge on October 26, 2024, 01:04:43 PM
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.
Title: Re: Small problem with GetCommandLine
Post by: Roland Stowasser on October 26, 2024, 03:46:16 PM
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)
Title: Re: Small problem with GetCommandLine
Post by: Charles Pegge on October 26, 2024, 08:51:41 PM
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.
Title: Re: Small problem with GetCommandLine
Post by: Roland Stowasser on October 27, 2024, 04:14:06 PM
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.
Title: Re: Small problem with GetCommandLine
Post by: Charles Pegge on October 29, 2024, 09:51:06 AM
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.
Title: Re: Small problem with GetCommandLine
Post by: James C. Fuller on October 29, 2024, 11:42:07 AM
Charles,
   Windows Defender does not like co2.exe

James
Title: Re: Small problem with GetCommandLine
Post by: Charles Pegge on October 29, 2024, 01:59:35 PM
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

Title: Re: Small problem with GetCommandLine
Post by: James C. Fuller on November 01, 2024, 10:37:02 AM
MS was pretty fast on this one. All is ok now

James
Title: Re: Small problem with GetCommandLine
Post by: Nicola on November 06, 2024, 10:55:47 PM
A big hello to everyone. 
I wanted to thank Charles for his excellent work. :)

Cheers
Title: Re: Small problem with GetCommandLine
Post by: Nicola on November 08, 2024, 04:08:09 PM
Hi Charles,
Wanting to include this information in the help, in which section could I place it?

nico
Title: Re: Small problem with GetCommandLine
Post by: Charles Pegge on November 08, 2024, 08:38:38 PM
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.
Title: Re: Small problem with GetCommandLine
Post by: Nicola on November 09, 2024, 12:21:38 AM
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
Title: Re: Small problem with GetCommandLine
Post by: Charles Pegge on November 10, 2024, 02:03:59 PM
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
Title: Re: Small problem with GetCommandLine
Post by: Nicola on November 10, 2024, 06:22:18 PM
ok.  8)