taviso / 123elf

A native port of Lotus 1-2-3 to Linux.
1.18k stars 59 forks source link

Running headless (without GUI/display) #131

Open MrBLJ opened 2 months ago

MrBLJ commented 2 months ago

Hi all,

First, thanks @taviso for your amazing work, it's been of great help.

I'm in a peculiar situation, where I have the regular need of converting xls files to wk1. So far, I'm making use of a script that handles this part like so :

# [...]
# Convert .csv to .wk1 using 123elf
command = f'{tool_path} -e /FIN{{ESC}}{{ESC}}{temp_csv_path}~/fs{{ESC}}{{ESC}}{{ESC}}{wk1_output_path}~/qy'
# [...]
# Using subprocess.run to execute the command
subprocess.run(command, shell=True, env=my_env )
# [...]

Short story : I export the xls to csv, then import to 123 using a macro, and finally save to wk1.

This works, when I run the script in the terminal but not if I run it as a service (which is the intended goal). After some experimentation, it looks like it's related to the GUI that's messing things up in the service. I get some weird errors like 123: [69B blob data].

Anyway, looking at 123 -h, there appear to be some kind of way to run this headless :

-n to run without using a video display

However I could not find any information about the autoretrieve file which seems to be needed.

I tried running, just to test : ./123 -n -w /home/me/test.wk1 -e /qy but the terminal screen goes blank and from here I can't do nothing.

▶ Before I start looking at alternate solutions, more complicated, like running the process under 'xvfb' :

  1. Do my explanations make sense ?
  2. Is there a way to execute 123elf from cli, without GUI ?
  3. Should I keep using macros, or is there a better way ?

Thanks for any insight you can provide and again, thanks a lot for your work !

taviso commented 2 months ago

Thanks for the clear report! Yes, your explanation makes sense, and it sounds like this should work... let me look into it!

I think as a temporary workaround maybe something like...

$ screen -dmS lotus env TERM=xterm 123 -w worksheet.wk3 -e '/qy'

If you want to debug any errors, add something like screen -L -Logfile debug.log ....

You can tell when it completes with pidwait -f lotus, or check the return code of screen -list lotus, I guess.

You could probably use tmux too, I'm just not as familiar with it as screen!

MrBLJ commented 2 months ago
$ screen -dmS lotus env TERM=xterm 123 -w worksheet.wk3 -e '/qy'

This is working well, thanks a lot I learned something new today !

In the interest of helping others that might have a similar situation than mine, if you want to convert xls files to lotus, here's my method :

[!NOTE] Commands are called from a python script, hence the specific syntax.

  1. Convert xls to csv using libreoffice :
    # Convert .xls to .csv using libreoffice
    subprocess.run([
    'libreoffice',
    '--headless',
    '--convert-to', 
    'csv:Text - txt - csv (StarCalc):44,34,ANSI,1,,0,false,true,true',
    filepath,
    '--outdir', 
    temp_folder
    ])
  2. Process the csv to add quotes to every cell, including the empty ones. As example. if the csv file contains a line with :
    data,,,data,,

    It should become :

    "data","","","data","",
  3. Use the command suggested by @taviso to convert the file using a macro :
    
    # Convert .csv to .wk1 using 123elf
    command = f'screen -dmS lotus env TERM=xterm {tool_path} -e /FIN{{ESC}}{{ESC}}{temp_csv_path}~/fs{{ESC}}{{ESC}}{{ESC}}{wk1_output_path}~/qy'

Using subprocess.run to execute the command

my_env = os.environ.copy() my_env["PATH"] = f"/usr/sbin:/sbin:{my_env['PATH']}" subprocess.run(command, shell=True, env=my_env )

krackout commented 2 months ago

Out of curiosity and if of course you can tell, why is xls needed in your situation to be converted to wk1? Does anybody still prefer to work on 1-2-3 for professional reasons? Personally the last time I met somebody demanding 1-2-3 over Excel was up until 2007! (Probably later also, I left that company on 2007. Due to her position the demand was fullfilled, using the last Windows version of 1-2-3).

On 2024-09-16 10:53 MrBLJ @.***> wrote:

$ screen -dmS lotus env TERM=xterm 123 -w worksheet.wk3 -e '/qy'

This is working well, thanks a lot I learned something new today !

In the interest of helping others that might have a similar situation than mine, if you want to convert xls files to lotus, here's my method :

Note

Commands are called from a python script, hence the specific syntax.

  1. Convert xls to csv using libreoffice :

Convert .xls to .csv using libreoffice

subprocess.run([ 'libreoffice', '--headless', '--convert-to', 'csv:Text - txt - csv (StarCalc):44,34,ANSI,1,,0,false,true,true', filepath, '--outdir', temp_folder ])

  1. Process the csv to add quotes to every cell, including the empty ones. As example. if the csv file contains a line with :

data,,,data,,

It should become :

"data","","","data","",

  1. Use the command suggested by @taviso to convert the file using a macro :

Convert .csv to .wk1 using 123elf

command = f'screen -dmS lotus env TERM=xterm {tool_path} -e /FIN{{ESC}}{{ESC}}{temp_csv_path}~/fs{{ESC}}{{ESC}}{{ESC}}{wk1_output_path}~ /qy'

Using subprocess.run to execute the command

my_env = os.environ.copy() my_env["PATH"] = f"/usr/sbin:/sbin:{my_env['PATH']}" subprocess.run(command, shell=True, env=my_env )

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

MrBLJ commented 2 months ago

Does anybody still prefer to work on 1-2-3 for professional reasons ?

I wouldn't say people prefer to use 1-2-3, the reality is that it still sees significant usage in professional environments (even in large companies, working in tech, R&D or industrial).

The main reason is the continued reliance on legacy hardware—not just old computers, but also the machines they control. These are often worth anywhere between $50 to $100k, are not upgraded but repaired over time (kind of a "Ship of Theseus" scenario). As long as they remain functional, companies will continue to use them.

As a result, even in 2024, some systems are still running WFW3.11, with data transferred via floppy disks. I'm working to improve this situation, but I have limited time and knowledge.