LB Booster
« CommandLine$ oddity »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:24am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: CommandLine$ oddity  (Read 695 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx CommandLine$ oddity
« Thread started on: Dec 9th, 2014, 3:37pm »

I'm getting confusing results from LB 4.04 when using the CommandLine$ variable and I wonder if anybody can shed some light. Firstly I created the following program:

Code:
    print CommandLine$
    wait 

I compiled this in LBB to the executable commandlinetest.exe and then tried running it using Start... Run... and from a command prompt:

From Start... Run...
Open: commandlinetest red yellow blue
opened a window containing red yellow blue

From a command prompt:
>commandlinetest red yellow blue
opened a window containing red yellow blue

I next created commandlinetest.tkn in LB 4.04 and copied run404.exe to commandlinetest.exe. Repeating the above tests:

From Start... Run...
Open: commandlinetest red yellow blue
opened a window containing red yellow blue

So far so ordinary, but:

From a command prompt:
>commandlinetest red yellow blue
opened a window containing commandlinetest red yellow blue

What? Surely using Start... Run... must give the same results as executing the program directly from a command prompt (I wouldn't know how to make them different if I wanted to) but it seems that with LB 4.04 they are different!

Am I going mad or is this a bug in LB? It would make it awkward to write a program which takes command-line parameters and may be run using both methods.

Richard.
User IP Logged

RobM
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 91
xx Re: CommandLine$ oddity
« Reply #1 on: Dec 10th, 2014, 11:25pm »

That is strange.

How does Windows send the command line to a program? (meaning how is it structured) Is it like a DLL call where the parameters are sometimes separated by a double chr$(0)?

Either way it would seem Windows is sending "commandlinetest" along with the regular command line variables.
« Last Edit: Dec 10th, 2014, 11:26pm by RobM » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: CommandLine$ oddity
« Reply #2 on: Dec 11th, 2014, 4:23pm »

on Dec 10th, 2014, 11:25pm, RobM wrote:
How does Windows send the command line to a program?

It is passed as the third parameter of WinMain, the 'C' prototype of which is as follows:

Code:
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow) 

szCmdLine is a NUL-terminated string containing the command line 'tail', i.e. any parameters, which is what LBB copies into CommandLine$.

It's also possible to retrieve the command line using the GetCommandLine API, which gives you the full command line (including the executable name at the beginning).

But, crucially, both methods give consistent results whether the program is run from a command prompt or from Start... Run... It's almost as though LB is using szCmdLine when executed from Start.. Run... and GetCommandLine when executed from a command prompt, but that makes no sense (and, anyway, how does it know?).

Richard.
User IP Logged

RobM
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 91
xx Re: CommandLine$ oddity
« Reply #3 on: Dec 11th, 2014, 6:21pm »

So LB must be using GetCommandLine but that does really explain why there would be a difference.

Either way, this is probably something that is done behind the scenes in Smalltalk and Carl wouldn't be able to fix it.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: CommandLine$ oddity
« Reply #4 on: Dec 11th, 2014, 9:36pm »

on Dec 11th, 2014, 6:21pm, RobM wrote:
Either way, this is probably something that is done behind the scenes in Smalltalk and Carl wouldn't be able to fix it.

I see there's currently a thread at the LB Community Forum which indicates that the problems with CommandLine$ go far deeper than I realised. Even when consistently run from a command prompt the contents of the variable depend on things like whether you enclose the program name in quotes or not!

If the issue is a fault in Smalltalk Carl should be able to workaround it by calling the GetCommandLine API himself (thereby bypassing Smalltalk's command line processing) and parsing it to return the wanted command 'tail' - which basically involves removing the initial (possibly quoted) path/filename of the executable.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls