Bug 143718 - when I convert word to pdf, appear a command window, after finished ,the command window disappear.
Summary: when I convert word to pdf, appear a command window, after finished ,the comm...
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
6.4.2.2 release
Hardware: x86 (IA32) Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-04 09:23 UTC by wuzhenyu
Modified: 2021-08-05 14:01 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wuzhenyu 2021-08-04 09:23:04 UTC
Description:
when I execute soffice --headless --convert-to pdf, appear a command window.After finished convert,the command window disappear.I have try other arguments,like --invisible,--minimized,--invisible,and install other version of libreoffice, such as 5.4.7.2 release

image:https://oscimg.oschina.net/oscnet/up-f5bfbe956a1d94815d3409e6b2e6c53c14e.png

Steps to Reproduce:
1.Execute soffice --headless --convert-to pdf by the javascript in website,a command window appear.
2.Finished convert,the command window disappear.

Actual Results:
A command window appear.

Expected Results:
Command window not appear.


Reproducible: Always


User Profile Reset: No



Additional Info:
My OS is windows 7,here is my javascript,thanks.

'use strict';

const fs = require('fs');
const path = require('path');
const async = require('async');
const tmp = require('tmp');
const { exec } = require('child_process');

exports.convert = (document, format, filter, callback) => {
    const tempDir = tmp.dirSync({prefix: 'libreofficeConvert_', unsafeCleanup: true});
    const installDir = tmp.dirSync({prefix: 'soffice', unsafeCleanup: true});
    return async.auto({
        soffice: (callback) => {
            let paths = [];
            switch (process.platform) {
                case 'darwin': paths = ['/Applications/LibreOffice.app/Contents/MacOS/soffice'];
                    break;
                case 'linux': paths = ['/usr/bin/libreoffice', '/usr/bin/soffice'];
                    break;
                case 'win32': 
                console.log('process.env')
                console.log(process.env['PROGRAMFILES(X86)'])
                console.log('PROGRAMFILES')
                console.log(process.env.PROGRAMFILES)
                paths = [
                    'C:/Program Files/LibreOffice/program/soffice.exe'
                    // path.join(process.env['PROGRAMFILES(X86)'], 'LIBREO~1/program/soffice.exe'),
                    // path.join(process.env['PROGRAMFILES(X86)'], 'LibreOffice/program/soffice.exe'),
                    // path.join(process.env.PROGRAMFILES, 'LibreOffice/program/soffice.exe'),
                ];
                console.log('break')
                console.log(paths)
                    break;
                default:
                    return callback(new Error(`Operating system not yet supported: ${process.platform}`));
            }

            return async.filter(
                paths,
                (filePath, callback) => fs.access(filePath, err => callback(null, !err)),
                (err, res) => {
                    if (res.length === 0) {
                        return callback(new Error('Could not find soffice binary'));
                    }

                    return callback(null, process.platform === 'win32' ? `"${res[0]}"` : res[0]);
                }
            );
        },
        saveSource: callback => fs.writeFile(path.join(tempDir.name, 'source'), document, callback),
        convert: ['soffice', 'saveSource', (results, callback) => {
            let command = `${results.soffice} --headless --invisible --convert-to ${format} `;
            if (filter !== undefined) {
                command += `:"${filter}"`;
            }
            command += ` --outdir ${tempDir.name} ${path.join(tempDir.name, 'source')}`;

            return exec(command, callback);
        }],
        loadDestination: ['convert', (results, callback) =>
            async.retry({
                times: 3,
                interval: 200
            }, (callback) => fs.readFile(path.join(tempDir.name, `source.${format}`), callback), callback)
        ]
    }, (err, res) => {
        tempDir.removeCallback();
        installDir.removeCallback();

        if (err) {
            return callback(err);
        }

        return callback(null, res.loadDestination);
    });
};
Comment 1 Mike Kaganski 2021-08-04 09:53:27 UTC
This is not a bug.

Don't use soffice.exe for console operation (even those that are performed in a Java code). soffice.exe is a Windows subsystem application, and when it needs to output messages to console (as is the case for --convert-to), it has to create a new console for that (just because it has no own console).

Starting from 6.3, there's a proper console application: soffice.com [1]. It reuses the console provided by the calling process (it might be redirected to a file, or whatever). Use it instead of soffice.exe.

[1] https://wiki.documentfoundation.org/ReleaseNotes/6.3#Windows
Comment 2 wuzhenyu 2021-08-05 09:12:40 UTC
(In reply to Mike Kaganski from comment #1)
> This is not a bug.
> 
> Don't use soffice.exe for console operation (even those that are performed
> in a Java code). soffice.exe is a Windows subsystem application, and when it
> needs to output messages to console (as is the case for --convert-to), it
> has to create a new console for that (just because it has no own console).
> 
> Starting from 6.3, there's a proper console application: soffice.com [1]. It
> reuses the console provided by the calling process (it might be redirected
> to a file, or whatever). Use it instead of soffice.exe.
> 
> [1] https://wiki.documentfoundation.org/ReleaseNotes/6.3#Windows

Mike,Thank you very much for your reply.
I use soffice.com instead of soffice.exe,but the Windows command line still appear.I have no idea resolve it.
Comment 3 Mike Kaganski 2021-08-05 09:22:13 UTC
Please read the documentation on the API that you use [1] - that is NodeJS' child_process.exec operation, and it has a 'windowsHide' option, that is documented to "Hide the subprocess console window that would normally be created on Windows systems. Default: false".

[1] https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
Comment 4 wuzhenyu 2021-08-05 14:01:46 UTC
(In reply to Mike Kaganski from comment #3)
> Please read the documentation on the API that you use [1] - that is NodeJS'
> child_process.exec operation, and it has a 'windowsHide' option, that is
> documented to "Hide the subprocess console window that would normally be
> created on Windows systems. Default: false".
> 
> [1]
> https://nodejs.org/api/child_process.
> html#child_process_child_process_exec_command_options_callback

Thank you,using this method, I solved my problem .