Does FBC compile some small code in command line?

New to FreeBASIC? Post your questions here.
Tourist Trap
Posts: 2756
Joined: Jun 02, 2015 16:24

Does FBC compile some small code in command line?

Postby Tourist Trap » Feb 22, 2019 14:27

Hello,

I wonder if there is a way to tell FBC to take a code simply quoted (and not placed within a file) as argument - in command line, like:

Code: Select all

fbc " 'freebasic code : beep : end"


?
marcov
Posts: 2751
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Does FBC compile some small code in command line?

Postby marcov » Feb 22, 2019 14:36

Yeah, that gets me thinking out of the box.

Or pipes ? Or maybe DBUS. Drag and drop to the compiler binary perhaps? Does DDE still exist ?

Seriously, for quick and dirty stuff a shebang usage of FB sounds best.
Last edited by marcov on Mar 02, 2019 14:14, edited 1 time in total.
counting_pine
Site Admin
Posts: 6169
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Does FBC compile some small code in command line?

Postby counting_pine » Feb 22, 2019 15:09

For very basic stuff, something like this might do on Windows:

Code: Select all

::fbrun.bat
@echo off
echo Running command: %*
echo %* > %TEMP%\fbrun.bas
fbc %TEMP%\fbrun.bas && %TEMP%\fbrun.exe

Code: Select all

fbrun print 10*4+2
Running: print 10*4+2
 42

Obviously adapt if necessary to make sure it can find fbc..

There will probably be issues with command line parameter escaping etc. In particular, characters like quotes, greater/less or caret signs might cause problems.

In general it's probably a lot easier in Linux bash, where escaping is more well-defined, so it's possible to specify arbitrary strings as command-line parameters.
Tourist Trap
Posts: 2756
Joined: Jun 02, 2015 16:24

Re: Does FBC compile some small code in command line?

Postby Tourist Trap » Feb 22, 2019 15:16

marcov wrote:Drag and drop to the compiler binary perhaps?

At least this, on windows is easy:

Code: Select all

'drop some file on the icon of this stuff

if command(1)<>"" then
    if exec("fbc.exe", command(1))<>0 then ? "fbc not found"
end if

sleep


counting_pine wrote:For very basic stuff, something like this might do on Windows:

Code: Select all

::fbrun.bat
@echo off
echo Running command: %*
echo %* > %TEMP%\fbrun.bas
fbc %TEMP%\fbrun.bas && %TEMP%\fbrun.exe

Code: Select all

fbrun print 10*4+2
Running: print 10*4+2
 42

Nice, thanks a lot.
UEZ
Posts: 318
Joined: May 05, 2017 19:59
Location: Germany

Re: Does FBC compile some small code in command line?

Postby UEZ » Feb 22, 2019 15:21

For such purposes an interpreter language such as Autoit is the better choice. Afaik, you can add a text file to the interpreter directly to parse and execute it.

I assume FB must compile the code before it can be executed.
Tourist Trap
Posts: 2756
Joined: Jun 02, 2015 16:24

Re: Does FBC compile some small code in command line?

Postby Tourist Trap » Mar 02, 2019 13:49

UEZ wrote:I assume FB must compile the code before it can be executed.

Yes but fbc is quite fast. Leaving asid autoIt that gives nighmares to my antivirus :), if you try PowerShell, you will probably agree that PowerShell is very slow, and probably slower than FB would be even if PowerShell is interpreted... and 100% native...
jj2007
Posts: 1161
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Does FBC compile some small code in command line?

Postby jj2007 » Mar 03, 2019 3:51

UEZ wrote:I assume FB must compile the code before it can be executed.
As Tourist Trap noted, fbc is pretty fast. I use my own editor (RichMasm) to build FB code, and it takes usually less than one second between hitting F5 and seeing the result. That is almost like using an interpreter. It requires an IDE or editor, though, that compiles the code "as is", i.e. without the need to hit Ctrl S first to save the content to disk.
UEZ
Posts: 318
Joined: May 05, 2017 19:59
Location: Germany

Re: Does FBC compile some small code in command line?

Postby UEZ » Mar 03, 2019 11:46

Tourist Trap wrote:
UEZ wrote:I assume FB must compile the code before it can be executed.

Yes but fbc is quite fast. Leaving asid autoIt that gives nighmares to my antivirus :), if you try PowerShell, you will probably agree that PowerShell is very slow, and probably slower than FB would be even if PowerShell is interpreted... and 100% native...


Well, a lot of malicious code is written in AutoIt and thus it is very hard to compile a clean exe for a AV app. For me PS is more for administrating the environment whereas AutoIt can more or less do the same but has more advantages in creating compiled apps which is usually faster than PS. I've written a complete screen capturing app with AutoIt and it's "pretty" fast for its conditions.

The main disadvantage for AutoIt is speed and that's the reason why I'm here. ^^ But it very easy to learn and has a lot of user defined functions which facilitating the work with winapi extremely.

jj2007 wrote:
UEZ wrote:I assume FB must compile the code before it can be executed.
As Tourist Trap noted, fbc is pretty fast. I use my own editor (RichMasm) to build FB code, and it takes usually less than one second between hitting F5 and seeing the result. That is almost like using an interpreter. It requires an IDE or editor, though, that compiles the code "as is", i.e. without the need to hit Ctrl S first to save the content to disk.

I didn't want to say that the compilation with FB takes too long, I just wanted to mention that the purpose for this an interpreter language such as Autoit might be the better choice.
jj2007
Posts: 1161
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Does FBC compile some small code in command line?

Postby jj2007 » Mar 03, 2019 17:52

UEZ wrote:I didn't want to say that the compilation with FB takes too long, I just wanted to mention that the purpose for this an interpreter language such as Autoit might be the better choice.
Once upon a time, people tested their code in a BASIC interpreter, and when they judged it OK, they compiled it to get the fast standalone version. I've done that for ages with GfaBasic. The interpreter was already fast enough for most purposes, but there was this extra kick when you compiled it - roughly a factor 3 faster.

But that was in the 1980s and '90s. Compiling a few thousand lines of Fortran IV on a PDP-11 was an occasion to have a coffee break with colleagues. Indeed, a BASIC interpreter was a much better choice for code that required testing and debugging (=100% of all code).

Today, the 20,000+ lines of my editor's source assemble in about one second. There is absolutely no need for an interpreter. Compiling an FB source with GCC is admittedly a bit slower, but the sources published in this forum compile typically in one second, too. If that is too much, use GAS. A full-fledged Windows GUI application takes half a second to compile with GAS.

Now one could argue that an interpreter offers something for debugging variables directly etc etc, but this is another topic (hint: you can use debug macros that can be switched off completely with conditional compilation).

Return to “Beginners”

Who is online

Users browsing this forum: Google [Bot] and 2 guests