Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Download a file and "execute"?

66 views
Skip to first unread message

Juge

unread,
Sep 2, 2019, 3:20:32 AM9/2/19
to
In normal webbrowser if I click on hyperlink and download a file, Windows asks whether I want to save the file or open it with some application. I have a program that fetches a file from a webserver and I would like to invoke a similar dialogue or I would simply like to open the file with the associated application.

My problem is that initially my files are either powerpoint or text files and my Tcl program runs in Linux and Windows. In Linux it might be that there is no way to handle the powerpoint.

So how can I invoke that option platform independent?

Arjen Markus

unread,
Sep 2, 2019, 7:01:19 AM9/2/19
to
The simplest way is to examine the global tcl_platform array. Here is the result from tclsh on my system:

% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(engine) = Tcl
tcl_platform(machine) = amd64
tcl_platform(os) = Windows NT
tcl_platform(osVersion) = 10.0
tcl_platform(pathSeparator) = ;
tcl_platform(platform) = windows
tcl_platform(pointerSize) = 8
tcl_platform(threaded) = 1
tcl_platform(user) = markus
tcl_platform(wordSize) = 4

You would want the "platform" element :).

Regards,

Arjen

Juge

unread,
Sep 2, 2019, 7:41:11 AM9/2/19
to
I am not sure, how that is going to help me...
I have already means of detecting whether my code is running under linux or windows that is not the case.

What I want to achieve is that I download a file from a server with my program and then I want the program to invoke a dialogue whether to "save" or "open with".

There are these kind of standard dialogues in both windows or linux. I am just not sure how to get something like that to lauch. It could be even that "exec <filename>" could get me what I want...

Juge

unread,
Sep 2, 2019, 7:49:57 AM9/2/19
to
In the end I just want Tcl program to launch Powerpoint if the file is powerpoint format or textpad if it is a text file. In Linux I would like to launch openoffice (if installed) or nedit for example.

Of course I would rather leave the choice open to a user, but there should be usually some link to registered filetypes and what to do with them?

Andreas Leitgeb

unread,
Sep 2, 2019, 7:50:20 AM9/2/19
to
Juge <jyrki.m...@gmail.com> wrote:
> What I want to achieve is that I download a file from a server with
> my program and then I want the program to invoke a dialogue whether
> to "save" or "open with".

I think, these dialogs are not system dialogs, but dialogs from the
respective browser.

Maybe you can start a browser with the download location and let the
browser "download" it from local disk.

Or even just pass the URL to browser instead of downloading it yourself.

Arjen Markus

unread,
Sep 2, 2019, 8:02:36 AM9/2/19
to
On Monday, September 2, 2019 at 1:49:57 PM UTC+2, Juge wrote:
> In the end I just want Tcl program to launch Powerpoint if the file is powerpoint format or textpad if it is a text file. In Linux I would like to launch openoffice (if installed) or nedit for example.
>
> Of course I would rather leave the choice open to a user, but there should be usually some link to registered filetypes and what to do with them?

Like Andreas said, these dialogs are probably defined by the browser. But to help out: you can use the [auto_execok] command to see if a file is "executable". If it is not (on Windows: not an executable, batch file or a file type for which there exists an associated program), it returns an empty string. Otherwise you can use the returned string to "execute" the file.

Regards,

Arjen

Juge

unread,
Sep 2, 2019, 8:03:57 AM9/2/19
to
Am Montag, 2. September 2019 13:50:20 UTC+2 schrieb Andreas Leitgeb:
>
> I think, these dialogs are not system dialogs, but dialogs from the
> respective browser.
>
> Maybe you can start a browser with the download location and let the
> browser "download" it from local disk.
>
> Or even just pass the URL to browser instead of downloading it yourself.

And is there no other alternative that correspond to simple action of double clicking a file in a file manager. Both linux and windows react to this in a certain way, if they know the file type or if they do not...this is what I would like to replicate

Rich

unread,
Sep 2, 2019, 9:25:28 AM9/2/19
to
Juge <jyrki.m...@gmail.com> wrote:
> Am Montag, 2. September 2019 09:20:32 UTC+2 schrieb Juge:
>> In normal webbrowser if I click on hyperlink and download a file,
>> Windows asks whether I want to save the file or open it with some
>> application.

No, the browser asks, not Windows.

>> My problem is that initially my files are either powerpoint or text
>> files and my Tcl program runs in Linux and Windows. In Linux it
>> might be that there is no way to handle the powerpoint.
>>
>> So how can I invoke that option platform independent?
>
> I am not sure, how that is going to help me...

That lets you know how to "launch" the downloaded file (the 'launch'
sequence is different).

> What I want to achieve is that I download a file from a server with
> my program and then I want the program to invoke a dialogue whether
> to "save" or "open with".

You have to implement that dialog yourself. That is not a standard
system dialog.

Then, for windows, investigate the documentation for the "start"
command.

For Linux (depending on if it is installed) investigate the
documentation of the 'xdg-open' command (note that not all Linux's you
encounter will have this command installed).

Robert Heller

unread,
Sep 2, 2019, 12:31:43 PM9/2/19
to
At Mon, 2 Sep 2019 04:41:08 -0700 (PDT) Juge <jyrki.m...@gmail.com> wrote:

>
> Am Montag, 2. September 2019 09:20:32 UTC+2 schrieb Juge:
> > In normal webbrowser if I click on hyperlink and download a file, Windows=
> asks whether I want to save the file or open it with some application. I h=
> ave a program that fetches a file from a webserver and I would like to invo=
> ke a similar dialogue or I would simply like to open the file with the asso=
> ciated application.=20
> >=20
> > My problem is that initially my files are either powerpoint or text files=
> and my Tcl program runs in Linux and Windows. In Linux it might be that th=
> ere is no way to handle the powerpoint.=20
> >=20
> > So how can I invoke that option platform independent?
>
> I am not sure, how that is going to help me...
> I have already means of detecting whether my code is running under linux or=
> windows that is not the case.
>
> What I want to achieve is that I download a file from a server with my prog=
> ram and then I want the program to invoke a dialogue whether to "save" or "=
> open with".=20
>
> There are these kind of standard dialogues in both windows or linux. I am j=
> ust not sure how to get something like that to lauch. It could be even that=
> "exec <filename>" could get me what I want...

Browsers have a database of what to just save, what program to execute (open
with), and whether to ask the user or not. Graphical file managers have
something similar as well. In mess-windows there is only a single
graphical file manager ["Windows Explorer"] and MacOSX has Finder. Under
Linux there are many graphical file managers and it is possible to not have a
graphical file manager at all.

Only under mess-windows and MacOSX is this raised to the level of 'system
standard dialogues'. There are no system standard dialogues under Linux at
all (even if it seems that way -- every GUI subsystem has its own dialogues
derived from whatever GUI toolkit it uses -- Gnome from GTK, KDE from Qt,
etc.).

>

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services

Christian Gollwitzer

unread,
Sep 2, 2019, 3:23:15 PM9/2/19
to
Am 02.09.19 um 14:03 schrieb Juge:
> Am Montag, 2. September 2019 13:50:20 UTC+2 schrieb Andreas Leitgeb:
>>
>> I think, these dialogs are not system dialogs, but dialogs from the
>> respective browser.
>>
>> Maybe you can start a browser with the download location and let the
>> browser "download" it from local disk.
>>
>> Or even just pass the URL to browser instead of downloading it yourself.
>
> And is there no other alternative that correspond to simple action of double clicking a file in a file manager.

Yes, there is. You asked for a dialog etc., which is why you got these
answers.

IIUC, you are looking for a command which does the same as
double-clicking the file in the file manager. This is possible on all 3
major platforms:

Windows: cmd /c start <URL>
Linux: xdg-open <URL>
macOS: open <URL>

<URL> can be anything, from a web url like http://www.google.com to a
local file.

Christian

Juge

unread,
Sep 3, 2019, 5:56:17 AM9/3/19
to
Am Montag, 2. September 2019 21:23:15 UTC+2 schrieb Christian Gollwitzer:
> IIUC, you are looking for a command which does the same as
> double-clicking the file in the file manager. This is possible on all 3
> major platforms:
>
> Windows: cmd /c start <URL>
> Linux: xdg-open <URL>
> macOS: open <URL>
>
> <URL> can be anything, from a web url like http://www.google.com to a
> local file.
>
> Christian

From what I gathered this will do pretty much what I want. After couple of tests in Windows it either opens a text file in notepad, pptx in Powerpoint and if it has no clue it asks. In Linux it is similar.

So thanks I think I can work on this...
0 new messages