|
Post by xxgeek on Jan 6, 2023 0:04:51 GMT
I have written a program that takes advantage of the CommandLine$ option. I have all the dll's etc in the same dir as the .bas, the .tkn, and the renamed jbrun2.exe files.
It works great if I use this line in the program that runs it. run "b2e.tkn ";DefaultDir$;"\b2e.bas,z:\, -b -i -j -p -t"
but if I use the renamed jbrun2.exe I get an error message from the renamed jbrun2.exe "Application Load Aborted" "File not found b2e.tkn" (the tkn file is right beside it) run "b2e.exe ";DefaultDir$;"\b2e.bas,z:\, -b -i -j -p -t" '(error message happens)
I get the same error when trying it from a command prompt in Windows. Yes, I have the command prompt opened in the same dir
Am I missing something? I don't understand why it works with the tkn file, but not the renamed exe file. btw - The help file says it should work using the renamed exe. No mention of the windows commandline - this may never work, don't know, but would like it working if possible.
The code checking CommandLine$ from the b2e.bas file
if mid$(CommandLine$, 2, 2) = ":\" then fname$ = word$(CommandLine$, 1, ",") if instr(CommandLine$, "-p") then p = 1 if instr(CommandLine$, "-b") then bas = 1 if instr(CommandLine$, "-j") then project = 1 if instr(CommandLine$, "-t") then tkn = 1 if instr(CommandLine$, "-i") then incbas = 1 exeDest$ = word$(CommandLine$, 2, ",") JBpath$ = "C:\Program Files (x86)\Just BASIC v2.0" command = 1 : goto [commandPath] end if
|
|
|
Post by Stefan Pendl on Jan 6, 2023 6:41:12 GMT
If you use the renamed EXE you also have to put the TKN file into the same folder, so the EXE finds it. Can you post a screen shot of the folder contents?
|
|
|
Post by Rod on Jan 6, 2023 8:15:53 GMT
It’s a Windows thing. There are two possibilities. The first is that a space in the path or file name causes part of the command line to be truncated. This is why we often suggest surrounding the path and file name with an additional pair of quotes. Don’t think it is that. Second possibility is that when you call the .exe that the current working directory is not actually defaultDir$ . Now you pass defaultDir$ as the path to the .bas but we don’t actually pass the path to the .tkn, it is assumed to be the current working directory. If we are not actually in that directory the .exe can’t find the .tkn.
My solution is to use a .bat file and change the directory with CD prior to calling the .exe but show us what startup$ and defaultdir$ contain and be sure the relevant files are in place and correctly named. Shortcuts for example often don’t start in the directory you need to be in.
|
|
|
Post by xxgeek on Jan 6, 2023 8:45:28 GMT
If the problem is a space in the name, or a defaultdir issue, the tkn wouldn't work either, but it does. All files are freshly made. tkn, bas, and renamed exe I run the file named makeEXE.bas it's contents = one line run DefaultDir$;"\b2e.tkn ";DefaultDir$;"\b2e.bas,z:\,-p -i -j -b -t" It works flawlessly. If I change b2e.tkn to b2e.exe the error occurs. Also JB is installed to the default dir c:\Program Files (x86)\Just Basic v2.0) And I get the same error from a command prompt. Here's a screenshot attempt, of all the files in the same folder. If you right click, and open in a new tab it is larger.
|
|
|
Post by tsh73 on Jan 6, 2023 9:31:35 GMT
The darned thing is broken. libertybasiccom.proboards.com/thread/352/command-line-path-parsing-bugslibertybasiccom.proboards.com/thread/1544/commandlinevariants I see are 1) use way you discovered works (do you really need that EXE called, may be calling TKN will work OK for you?) 2) fiddle with ways shown in second thread (fake -f switch, adding path to TKN, adding quotes, no extra spaces) Might end up working. Might as well not. Will add it's own mess just to circumvent bugs. 3) ditch that broken thing, try to use something else (say write params in a file, and make your program read that file.) EDIT Going along(2)
run "b2e.exe ";DefaultDir$;"\b2e.tkn";" -f"+qq$;DefaultDir$;"\b2e.bas,z:\, -b -i -j -p -t"+qq$
ends with CommandLine$ f"C:\WRK\JB\tst b2e\b2e.bas,z:\, -b -i -j -p -t"
|
|
|
Post by Rod on Jan 6, 2023 10:42:14 GMT
Not finding the .tkn and spaces in commmand line are two separate problems.
If the .exe is not finding the .tkn you are not in the dir you expect. At the command prompt where it fails type DIR, does it list the files you need?
If it lists directories that’s no good, you need to be inside the working directory and the .tkn needs to be listed.
|
|
|
Post by xxgeek on Jan 6, 2023 18:37:48 GMT
Ok, problem fixed Thanks for all the help and ideas to try.
Here's what is up, there is no bug in CommandLine$ It is just very picky about it's contents. I had tried so many variations of the following line already I almost joined the "There is a bug" crowd too.
This works q$ = chr$(34) run q$;DefaultDir$;"\b2e.exe"+q$+" "+q$+DefaultDir$+"\b2e.bas,"+q$+"z:\,-p-i-j-b-t" And this works run q$;DefaultDir$;"\b2e.exe";q$;" ";q$;DefaultDir$;"\b2e.bas,";q$;"z:\,-p-i-j-b-t"
I could get away with removing DefaultDir$ and just use b2e.exe as the path and that works too.
After wrapping the quotes around the file paths it is working the same as if it was using the tkn now, great. The tkn file is found now Thanks. Exactly what I was hoping for.
Once the quotes are there in the file paths, I had to adjust my code in the .bas file to allow for those extra characters being there, and then the whole thing fell in place. From if mid$(CommandLine$, 2, 2) = ":\" then to if mid$(CommandLine$, 3, 2) = ":\" then (3 spaces in now, not 2 because the extra " in the path.
Still working on a way to use it from a command prompt. Will report back if/when I get it right. Command prompt doesn't like the quotes lol - I gotta laugh or I'll go nuts. There's always something that doesn't want to play ball. Good thing I was born a ball basher.
So, proof there is no bug at least. Thanks again gentlemen, can't get better help anywhere else.
When I get this finished it will be a commandline app able to create single exe files from a user selected, or commanded, .bas file with no user intervention other than to select the .bas file, and , if desired, where to put it, from the commandline, or from the GUI. There will be more options/switches than what appears here as well. Basically a more robust BAS2EXE.
@ Rod tsh73 and Brandon Parker. Your help is, and has been, instrumental in all my endeavors whether solicited or not. Your posts are always informative and to the point. Very much appreciated. EDIT - Ooops, I meant to include Stefan Pendl, got the names mixed up. I had just got back from reading a thread in LB forums where Brandon was explaining this issue.
@ Anyone else reading along. The main thing is "Never give up", keep trying no matter the depressing outcomes encountered.
|
|
|
Post by Rod on Jan 6, 2023 20:08:55 GMT
Printing the line rather than running it will show the exact issues with spaces hidden inside defaultdir$ and other hidden variables. Only when we see where these space breaks are can we properly understand the power of enveloping with chr$(34)
We should actually create a routine that replaces the spaces with ! To show more clearly where they are. And how they impact the run command.
|
|
|
Post by tsh73 on Jan 6, 2023 20:53:16 GMT
This is quote from The Witcher books. One of dwarfs said this to Herald:
Now I am pretty sure I can tell the bug without it kicking me. If program makes you jump through hoops just to work as it supposed to - that's definitely a bug.
Ah well. Glad you made if behaving. For me, I was able to make it work by enclosing paths with quotes with this function
function enq$(s$) q$ = chr$(34) s$=trim$(s$) if left$(s$,1)<>q$ THEN s$=q$+s$ if right$(s$,1)<>q$ THEN s$=s$+q$ enq$=s$ end function
and it works form command line as well
b2e.exe "C:\WRK\JB\tst b2e\b2e.bas" z:\ -p-i-j-b-t but from JB, there is a difference between b2e.exe and "b2e.exe":
print enq$("b2e.exe")+" "+enq$(DefaultDir$+"\b2e.bas")+" "+ "z:\ -p-i-j-b-t" run enq$("b2e.exe")+" "+enq$(DefaultDir$+"\b2e.bas")+" "+ "z:\ -p-i-j-b-t"
produces command line
"C:\WRK\JB\tst b2e\b2e.bas" z:\ -p-i-j-b-t while
print "b2e.exe"+" "+enq$(DefaultDir$+"\b2e.bas")+" "+ "z:\ -p-i-j-b-t" run "b2e.exe"+" "+enq$(DefaultDir$+"\b2e.bas")+" "+ "z:\ -p-i-j-b-t"
produces
z:\ -p-i-j-b-t
I don't like the fact that one needs some special version of word$ to parse this stuff
"C:\WRK\JB\tst b2e\b2e.bas" z:\ -p-i-j-b-t
|
|
|
Post by xxgeek on Jan 6, 2023 21:01:11 GMT
Printing the line rather than running it will show the exact issues with spaces hidden inside defaultdir$ and other hidden variables. Only when we see where these space breaks are can we properly understand the power of enveloping with chr$(34) We should actually create a routine that replaces the spaces with ! To show more clearly where they are. And how they impact the run command. Yes, I've been doing pretty much that method all along Rod. I've managed to get it working from a command prompt now too. In my main app I've removed the delimiter I was using ( a comma), and just went with the default (space) if word$(CommandLine$, 1) = "b2e" then print CommandLine$ fname$ = word$(CommandLine$, 1) if instr(CommandLine$, "-p") then p = 1 if instr(CommandLine$, "-b") then bas = 1 if instr(CommandLine$, "-j") then project = 1 if instr(CommandLine$, "-t") then tkn = 1 if instr(CommandLine$, "-i") then incbas = 1 exeDest$ = word$(CommandLine$, 2) : exeDest$ = right$(exeDest$, len(exeDest$)-1) JBpath$ = "C:\Program Files (x86)\Just BASIC v2.0"
I also took out the full path. Below, the b2e is the app to be run. The z:\ is the dir to save the exe file created. The -b-i-j-p-t are some of the switches used. -b for backup -i for include source file in the exe -j to keep the project dir created -p to add a password to the exe file -t to save the tkn file created There will also be switches to append the date, time, and probably a version# to the exe filename. Maybe more as I delve into that end now I've conquered (with all the help) making it work. To run it from a Command Prompt now I use. b2e -z:\ -b-i-j-p-t Oops EDIT - wrong line above, should read b2e b2e.bas bas-z:\ -b-i-j-p-t And I can see this will have issues with files that have spaces in their names, or paths, so I'll have to wrap quotes to include such files. Though I never name a file with spaces, there is always those who do, and plenty of paths could have spaces that users, and myself, may use. Adding that - before z:\ made all the difference. Without it, the error occurs. A tip from a post in LB forums re: Brandon Parker from a link tsh73 provided above. Good reading for anyone working with CommandLine$ It works flawlessly, and all the switches do their respective jobs. I don't really understand why, but... I should have eaten my pride and asked about this days ago. Ego is one of mans best, and worst, friends. Thanks again for all the time you take, and the others take, to help out in these forums.
|
|
|
Post by xxgeek on Jan 6, 2023 21:14:21 GMT
tsh73 you were posting as I typed my last post.
I realize there will be more than one way to skin this cat. I'm sticking with what I have that is working, and I've made 5 backups of the whole thing lol It's not gonna bite my a$$ this time around with one of my dumb overwrites..
It's been a long time working on this for me, almost 2 years on and off trying different ways.
In fact I think I tried some of the ways that work, but at the time other issues were getting in my way tricking me into believing my efforts were in vain. After all this experimenting over the last few days, I've learned a lot.
Many thanks tsh73, you're always there when someone needs your help. Going above and beyond any expectations. Kinda makes a guy wish he could go back in time, and select the teachers he wants teaching him, and avoid those lousy teachers he had with bigger ego's than his own.
|
|
|
Post by xxgeek on Jan 6, 2023 22:14:56 GMT
I'm going to try and get this app eventually to installed to system32 dir so I can run it from a command line in any dir, and also have it appear in my right click menu's as an option. Like : Create Single EXE From BAS file. I better add a -H option for a help menu, so I don't forget how to use it. Looking forward to the headaches, but more to the ease of creation of the single exe files. Then on to create an app for batch creations, doing 10n's of files one after the other.
|
|
|
Post by xxgeek on Jan 11, 2023 1:35:51 GMT
I would like to simplify an explanation, According to my own investigation, if I can.
Basically, attention should be given more to what is received in CommandLine$ than what is expected(as Rod has pointed out), and the programmer can take advantage of this "bug" ?
syntax for b2e b2e -sourceFilePath -destinationFilePath /includeSource /backupSource /keepProjectDir /backupTKNfile /passwordEXEfile /v'number'
When I run "b2e -someFile.bas -z:\ /i / b /kp /t /pw /dt /v I expect b2e to open and create an exe file using someFile.bas and use all the switches. I get the error "Abort Load" "Can't find someFile.tkn" because there is no \ in the source file(someFile.bas)(It 'IS' in the same dir as the tkn = DefaultDir$) So I add the \ like so run "b2e -\someFile.bas -\z:\ /i / b /kp /t /pw /dt /v
I still get an error, but at least it now comes from 'MY' app, and not the system. (take note of this, it's the key)
What I get in my app for CommandLine$ is b2e -\someFile.bas -z:\ /i / b /kp /t /pw /dt /v That's right, I get the entire line used at the command prompt. Strange, but true. A bug? I guess so, but a nice one.
Now, in my app I just need to filter out the \, because later on I'm using that path, and don't want the \ in my filename. But another problem occurred, my app "Can't find the file". I need a full path, and someFile.bas is not a full path. So, I make it a full path by programming in if (after I filter out the - and the \ of course), there is no \ in the source file, then sourceFile$ = DefaultDir$;"\";sourceFile$
My app starts up, in Command Mode, and runs using all the switches, creates the tkn, the project dir with all the runtime support files(dll's, sll's,the created tkn file and the renamed run451.exe file. Then goes on to use IEXPRESS to create a single exe file using the project dir files.
As you can see, no matter what CommandLine$ sends to your app, as long as it sends "something you can work with" and you understand the "bug" then anything is possible.
Adding additional filters to 'my app' allows the user to use a few different variations of the syntax, and helps ensure against crashes when improper syntax is used. eg: using b2e (alone opens the GUI, instead of using command mode) using b2e -\some.bas (runs as epected in command mode, but with no destPath it defaults to a pre-programmed default destPath) using b2e -\some.bas -z\ (runs as expected, and the exe file is created in z:\
Switches were never a problem, so won't go into that end. Still working on bullet proofing it.
Will continue to investigate this 'bug'? as well.
I hope others can use this info if/when they deal with CommandLine$
Here's the code my app currently uses for checking CommandLine$ - still not perfected, but working well.
Print statements are for testing to see what, if anything, I get from CommandLine$ and my variables before and after running the filters.
if CommandLine$ <> "" then if not(instr(CommandLine$, ".bas")) then notice "No Source File Path Detected";chr$(13);" -> BAS2EXE will Run in GUI Mode" : goto [GUI] print "before checking CommandLine$ =";CommandLine$ sourc3$ = word$(CommandLine$, 3) sourc2$ = word$(CommandLine$, 2) sourc1$ = word$(CommandLine$, 1) sourc = 1 if instr(sourc1$, ".bas") then fname$ = word$(CommandLine$, 1) : goto [getDest]' : fname$ = right$(fname$, len(fname$)-1) sourc = 2 if instr(sourc2$, ".bas") then fname$ = word$(CommandLine$, 2) : goto [getDest]' : fname$ = right$(fname$, len(fname$)-1) sourc = 3 if instr(sourc3$, ".bas") then fname$ = word$(CommandLine$, 3) [getDest] fname$ = trim$(fname$) : fname$ = trim$(fname$) if right$(fname$, 1) = chr$(34) then fname$ = left$(fname$, len(fname$)-1) if left$(fname$, 1) = chr$(34) then fname$ = right$(fname$, len(fname$)-1) if left$(fname$ ,1) = "-" then fname$ = right$(fname$, len(fname$)-1) if left$(fname$ ,1) = "\" then fname$ = right$(fname$, len(fname$)-1) if not(instr(fname$, ":\")) and instr(fname$, ".bas") then fname$ = DefaultDir$;"\";fname$ fname$ = trim$(fname$) : fname$ = trim$(fname$) if left$(fname$ ,1) = "\" then fname$ = right$(fname$, len(fname$)-1) print "fname$ = ";fname$ dest$ = word$(CommandLine$, 2) if instr(dest$, ":\") and sourc = 1 then exeDest$ = word$(CommandLine$, 2) : goto [gotDest]' : exeDest$ = right$(exeDest$, len(exeDest$)-1) dest$ = word$(CommandLine$, 3) if instr(dest$, ":\") and sourc = 2 then exeDest$ = word$(CommandLine$, 3) : goto [gotDest] ' ALL CommandLine options default to false until User uses switch options dest$ = word$(CommandLine$, 4) if instr(dest$, ":\") and sourc = 3 then exeDest$ = word$(CommandLine$, 4) : goto [gotDest]' : exeDest$ = right$(exeDest$, len(exeDest$)-1) notice "No Destination Path Detected";chr$(13);" EXE file will be saved to";chr$(13);DefaultDir$;"\EXE" : exeDest$ = DefaultDir$;"\EXE" [gotDest] if right$(exeDest$, 1) = chr$(34) then exeDest$ = left$(exeDest$, len(exeDest$)-1) if left$(exeDest$, 1) = chr$(34) then exeDest$ = right$(exeDest$, len(exeDest$)-1) if left$(exeDest$ , 1) = "-" then exeDest$ = right$(exeDest$, len(exeDest$)-1) if instr(CommandLine$, "/pw") then p = 1 'password - adds password to bas file - EXE needs it to RUN defaults to false 0 if instr(CommandLine$, "/b") then bas = 1 'dated bas file backup - defaults to true 1 if instr(CommandLine$, "/kp ") then project = 1 'keep the project folder - defaults to false 0- kill\delete it if instr(CommandLine$, "/t") then tkn = 1 'dated tkn file backup - defaults to true 1 if instr(CommandLine$, "/ib") then incbas = 1 'includes the bas file in the EXE created - defaults to false 0 if instr(CommandLine$, "/v") then ve = 1 ' appends a version number to the EXE filename - defaults to false - 0 if instr(CommandLine$, "/dt") then dt = 1 ' appends the date and time top the EXE file - defaults to true print "after manipulating fname$ = ";fname$ print "after manipulating exeDest$ = ";exeDest$ print "sourc = ";sourc JBpath$ = "C:\Program Files (x86)\Just BASIC v2.0" command = 1 : goto [commandPath] end if [GUI] 'blah blah
|
|