Opening a document in the os

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Opening a document in the os

Rob Vens
I was under the impression that I could do the following:
ExternalProcess defaultClass cshOne: '"c:\Mijn Projecten\Privé\Correspondentie\Postvak Uit\Brieven\Belastingdienst 11 oktober 1999.pdf"'
resulting in Acrobat starting up and showing the file.
However I tried and nothing happened. Is there a way to tell the os I want it to open a file?
Reply | Threaded
Open this post in threaded view
|

Re: Opening a document in the os

Charles A. Monteiro-2
Well, in Windows and if you have the Windows Goodies package loaded you  
can do this:

'myAdobeDocument.pdf' asFilename startAssociatedApplication

I'm not sure if this start by associatiated file type thing was ever  
implemented for Linux and I doubt if it has been done across the board.

-Charles

On Thu, 02 Mar 2006 10:26:04 -0500, Rob Vens <[hidden email]> wrote:

> I was under the impression that I could do the following:
> ExternalProcess defaultClass cshOne: '"c:\Mijn
> Projecten\Privé\Correspondentie\Postvak Uit\Brieven\Belastingdienst 11
> oktober 1999.pdf"'
> resulting in Acrobat starting up and showing the file.
> However I tried and nothing happened. Is there a way to tell the os I  
> want
> it to open a file?



--
Charles A. Monteiro

Reply | Threaded
Open this post in threaded view
|

Re: Opening a document in the os

Rob Vens
Well I found the culprit: I had a non-ascii character in my path: "Privé" (the last character). It seems that when this is the case, there is a problem in giving this to the command interpreter.
Is there anything I can do about this?

 
2006/3/2, Charles A. Monteiro <[hidden email]>:
Well, in Windows and if you have the Windows Goodies package loaded you
can do this:

'myAdobeDocument.pdf ' asFilename startAssociatedApplication

I'm not sure if this start by associatiated file type thing was ever
implemented for Linux and I doubt if it has been done across the board.

-Charles

On Thu, 02 Mar 2006 10:26:04 -0500, Rob Vens < [hidden email]> wrote:

> I was under the impression that I could do the following:
> ExternalProcess defaultClass cshOne: '"c:\Mijn
> Projecten\Privé\Correspondentie\Postvak Uit\Brieven\Belastingdienst 11
> oktober 1999.pdf"'
> resulting in Acrobat starting up and showing the file.
> However I tried and nothing happened. Is there a way to tell the os I
> want
> it to open a file?



--
Charles A. Monteiro

Reply | Threaded
Open this post in threaded view
|

Re: Opening a document in the os

Mark Pirogovsky-3
You have to use one of the windows API to convert the filename in
question into the short form.

Also try to use MinimalShellInterface open:''.  I think it is part of
the WindowGoodies or WinProcess packs.

Win32SystemSupport class

convertLongFileName: aFileName
        "!!! NOTE: if file doesn't exist the empty string is returned"
        "self convertLongFileName: 'y:\foo bar\bar too far.txt'"
       

        | xif |
        xif := self new.
        ^self convertLongFileName: aFileName withExtInt: xif


convertLongFileName: aFileName withExtInt: xif
        "Given a long windows path name, return the corresponding short path,
if available. Note that this is not supported on Windows NT or 95, in
which case we will just give back the long path again. Likewise if
there's an error calling the function (indicated by a return code of zero)"

        "self convertLongFileName: 'd:\Program Files\hh'"

        | resultLength longName shortPath |
       
        ^[shortPath := xif LPTSTR gcMalloc: xif MAX_PATH.
        resultLength := xif
                                GetShortPathName: aFileName
                                into: shortPath
                                withBuffer:  xif MAX_PATH.
        longName := shortPath copyCStringFromHeap.
        resultLength = 0 ifTrue: [aFileName] ifFalse: [longName]]
                        on: Error
                        do: [:ex | ex returnWith: aFileName]
        "@__markp February 11, 2004 3:06:59 pm"
        "@__markp April 29, 2004 11:52:34 pm"


Win32SystemSupport

GetShortPathName: lpszLongPath into: lpszShortPath withBuffer: cchBuffer
        <C: DWORD _wincall GetShortPathNameA(
   LPCTSTR lpszLongPath,
   LPTSTR lpszShortPath,
   DWORD cchBuffer
)
 >
        ^self externalAccessFailedWith: _errorCode

        "@__markp February 11, 2004 3:00:22 pm"
        "@__markp April 29, 2004 11:40:02 pm"

Rob Vens wrote:

> Well I found the culprit: I had a non-ascii character in my path:
> "Privé" (the last character). It seems that when this is the case, there
> is a problem in giving this to the command interpreter.
> Is there anything I can do about this?
>
>  
> 2006/3/2, Charles A. Monteiro <[hidden email]
> <mailto:[hidden email]>>:
>
>     Well, in Windows and if you have the Windows Goodies package loaded you
>     can do this:
>
>     'myAdobeDocument.pdf ' asFilename startAssociatedApplication
>
>     I'm not sure if this start by associatiated file type thing was ever
>     implemented for Linux and I doubt if it has been done across the board.
>
>     -Charles
>
>     On Thu, 02 Mar 2006 10:26:04 -0500, Rob Vens < [hidden email]
>     <mailto:[hidden email]>> wrote:
>
>      > I was under the impression that I could do the following:
>      > ExternalProcess defaultClass cshOne: '"c:\Mijn
>      > Projecten\Privé\Correspondentie\Postvak
>     Uit\Brieven\Belastingdienst 11
>      > oktober 1999.pdf"'
>      > resulting in Acrobat starting up and showing the file.
>      > However I tried and nothing happened. Is there a way to tell the os I
>      > want
>      > it to open a file?
>
>
>
>     --
>     Charles A. Monteiro
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Opening a document in the os

Alan Knight-2
In reply to this post by Rob Vens
It looks like the string gets more or less passed directly to C, and DLLCC will probably do a default conversion to bytes and give that to the OS. If that conversion isn't right, you might need to either change its default conversion, or you could see if doing a convert to byte array in the encoding that your OS is expecting and passing that down would work.

At 10:41 AM 3/2/2006, Rob Vens wrote:
Well I found the culprit: I had a non-ascii character in my path: "Privé" (the last character). It seems that when this is the case, there is a problem in giving this to the command interpreter.
Is there anything I can do about this?

 
2006/3/2, Charles A. Monteiro <[hidden email]>:
Well, in Windows and if you have the Windows Goodies package loaded you
can do this:

'myAdobeDocument.pdf ' asFilename startAssociatedApplication

I'm not sure if this start by associatiated file type thing was ever
implemented for Linux and I doubt if it has been done across the board.

-Charles

On Thu, 02 Mar 2006 10:26:04 -0500, Rob Vens < [hidden email]> wrote:

> I was under the impression that I could do the following:
> ExternalProcess defaultClass cshOne: '"c:\Mijn
> Projecten\Privé\Correspondentie\Postvak Uit\Brieven\Belastingdienst 11
> oktober 1999.pdf"'
> resulting in Acrobat starting up and showing the file.
> However I tried and nothing happened. Is there a way to tell the os I
> want
> it to open a file?



--
Charles A. Monteiro


--
Alan Knight [|], Cincom Smalltalk Development

"The Static Typing Philosophy: Make it fast. Make it right. Make it run." - Niall Ross
Reply | Threaded
Open this post in threaded view
|

Re: Opening a document in the os

Rob Vens
A simple trick I found out was converting the file name to an URI, as follows (self uri returns the string of an url that was obtained by getting the filename with a file dialog, and converting it to an URI):

openDocument
 "On Windows, start the associated application for the file. On other platforms, do nothing."

 ExternalProcess defaultClass
     shOne: 'cmd /x /c start ' , self uri value asURI asString.
 

or:

ExternalInterface currentPlatform first == #win32
  ifTrue:
   [Win32SystemSupport CreateDetachedProcess: nil
    arguments: 'cmd /x /c start ' , self uri value asURI asString]
  ifFalse: [Dialog warn: #OnlyAvailableOnWindows << #moneyCat]


 
2006/3/2, Alan Knight <[hidden email]>:
It looks like the string gets more or less passed directly to C, and DLLCC will probably do a default conversion to bytes and give that to the OS. If that conversion isn't right, you might need to either change its default conversion, or you could see if doing a convert to byte array in the encoding that your OS is expecting and passing that down would work.


At 10:41 AM 3/2/2006, Rob Vens wrote:
Well I found the culprit: I had a non-ascii character in my path: "Privé" (the last character). It seems that when this is the case, there is a problem in giving this to the command interpreter.
Is there anything I can do about this?

 
2006/3/2, Charles A. Monteiro <[hidden email]>:
Well, in Windows and if you have the Windows Goodies package loaded you
can do this:

'myAdobeDocument.pdf ' asFilename startAssociatedApplication

I'm not sure if this start by associatiated file type thing was ever
implemented for Linux and I doubt if it has been done across the board.

-Charles

On Thu, 02 Mar 2006 10:26:04 -0500, Rob Vens < [hidden email]> wrote:

> I was under the impression that I could do the following:
> ExternalProcess defaultClass cshOne: '"c:\Mijn
> Projecten\Privé\Correspondentie\Postvak Uit\Brieven\Belastingdienst 11
> oktober 1999.pdf"'
> resulting in Acrobat starting up and showing the file.
> However I tried and nothing happened. Is there a way to tell the os I
> want
> it to open a file?



--
Charles A. Monteiro


--
Alan Knight [|], Cincom Smalltalk Development
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.cincom.com/smalltalk" target="_blank">http://www.cincom.com/smalltalk

"The Static Typing Philosophy: Make it fast. Make it right. Make it run." - Niall Ross

Reply | Threaded
Open this post in threaded view
|

RE: Opening a document in the os

Boris Popov, DeepCove Labs (SNN)
In reply to this post by Rob Vens
Oh so many ways of doing the same thing... ;)

With Windows-Goodies you can also do,

MinimalShellInterface openFile: 'c:\document.pdf'

Cheers!

-Boris

--
+1.604.689.0322
DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5

[hidden email]

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any
attachments.

Thank you.

-----Original Message-----
From: Rob Vens [mailto:[hidden email]]
Sent: Thursday, March 02, 2006 10:34 AM
To: Alan Knight
Cc: Charles A. Monteiro; [hidden email]
Subject: Re: Opening a document in the os

A simple trick I found out was converting the file name to an URI, as
follows (self uri returns the string of an url that was obtained by getting
the filename with a file dialog, and converting it to an URI):


openDocument
 "On Windows, start the associated application for the file. On other
platforms, do nothing."

 ExternalProcess defaultClass
     shOne: 'cmd /x /c start ' , self uri value asURI asString.
 

or:

ExternalInterface currentPlatform first == #win32
  ifTrue:
   [Win32SystemSupport CreateDetachedProcess: nil
    arguments: 'cmd /x /c start ' , self uri value asURI asString]
  ifFalse: [Dialog warn: #OnlyAvailableOnWindows << #moneyCat]


 
2006/3/2, Alan Knight <[hidden email]>:

        It looks like the string gets more or less passed directly to C, and
DLLCC will probably do a default conversion to bytes and give that to the
OS. If that conversion isn't right, you might need to either change its
default conversion, or you could see if doing a convert to byte array in the
encoding that your OS is expecting and passing that down would work.
       
       
        At 10:41 AM 3/2/2006, Rob Vens wrote:
       

                Well I found the culprit: I had a non-ascii character in my
path: "Privé" (the last character). It seems that when this is the case,
there is a problem in giving this to the command interpreter.
                Is there anything I can do about this?
               
                 
                2006/3/2, Charles A. Monteiro <[hidden email]>:
               

                        Well, in Windows and if you have the Windows Goodies
package loaded you
                       
                        can do this:
                       
                       
                        'myAdobeDocument.pdf ' asFilename
startAssociatedApplication
                       
                       
                        I'm not sure if this start by associatiated file
type thing was ever
                       
                        implemented for Linux and I doubt if it has been
done across the board.
                       
                       
                        -Charles
                       
                       
                        On Thu, 02 Mar 2006 10:26:04 -0500, Rob Vens <
[hidden email]> wrote:
                       
                       
                        > I was under the impression that I could do the
following:
                       
                        > ExternalProcess defaultClass cshOne: '"c:\Mijn
                       
                        > Projecten\Privé\Correspondentie\Postvak
Uit\Brieven\Belastingdienst 11
                       
                        > oktober 1999.pdf"'
                       
                        > resulting in Acrobat starting up and showing the
file.
                       
                        > However I tried and nothing happened. Is there a
way to tell the os I
                       
                        > want
                       
                        > it to open a file?
                       
                       
                       
                       
                        --
                       
                        Charles A. Monteiro
                       
                       


       
        --
        Alan Knight [|], Cincom Smalltalk Development
        [hidden email]
        [hidden email]
        http://www.cincom.com/smalltalk

        "The Static Typing Philosophy: Make it fast. Make it right. Make it
run." - Niall Ross



smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: Opening a document in the os

Thomas Brodt

Just a hint:

We first also used  WinProcess cshOne to open a file, but had problems with
it.
On some customer installations this didn't work because of security issues,
I assume (opening a cmd on windows as a restricted user.)

The MinimalShellInterface approach however worked on this secure
installation, so I didn't investigate any further to confirm this was the
real cause.

Thomas


> -----Original Message-----
> From: Boris Popov [mailto:[hidden email]]
> Sent: Thursday, March 02, 2006 7:43 PM
> To: [hidden email]; Alan Knight
> Cc: Charles A. Monteiro; [hidden email]
> Subject: RE: Opening a document in the os
>
> Oh so many ways of doing the same thing... ;)
>
> With Windows-Goodies you can also do,
>
> MinimalShellInterface openFile: 'c:\document.pdf'
>
> Cheers!
>
> -Boris
>
> --
> +1.604.689.0322
> DeepCove Labs Ltd.
> 4th floor 595 Howe Street
> Vancouver, Canada V6C 2T5
>
> [hidden email]
>
> CONFIDENTIALITY NOTICE
>
> This email is intended only for the persons named in the message
> header. Unless otherwise indicated, it contains information that is
> private and confidential. If you have received it in error, please
> notify the sender and delete the entire message including any
> attachments.
>
> Thank you.
>
> -----Original Message-----
> From: Rob Vens [mailto:[hidden email]]
> Sent: Thursday, March 02, 2006 10:34 AM
> To: Alan Knight
> Cc: Charles A. Monteiro; [hidden email]
> Subject: Re: Opening a document in the os
>
> A simple trick I found out was converting the file name to an URI, as
> follows (self uri returns the string of an url that was
> obtained by getting
> the filename with a file dialog, and converting it to an URI):
>
>
> openDocument
>  "On Windows, start the associated application for the file. On other
> platforms, do nothing."
>
>  ExternalProcess defaultClass
>      shOne: 'cmd /x /c start ' , self uri value asURI asString.
>  
>
> or:
>
> ExternalInterface currentPlatform first == #win32
>   ifTrue:
>    [Win32SystemSupport CreateDetachedProcess: nil
>     arguments: 'cmd /x /c start ' , self uri value asURI asString]
>   ifFalse: [Dialog warn: #OnlyAvailableOnWindows << #moneyCat]
>
>
>  
> 2006/3/2, Alan Knight <[hidden email]>:
>
> It looks like the string gets more or less passed
> directly to C, and
> DLLCC will probably do a default conversion to bytes and give
> that to the
> OS. If that conversion isn't right, you might need to either
> change its
> default conversion, or you could see if doing a convert to
> byte array in the
> encoding that your OS is expecting and passing that down would work.
>
>
> At 10:41 AM 3/2/2006, Rob Vens wrote:
>
>
> Well I found the culprit: I had a non-ascii
> character in my
> path: "Privé" (the last character). It seems that when this
> is the case,
> there is a problem in giving this to the command interpreter.
> Is there anything I can do about this?
>
>
> 2006/3/2, Charles A. Monteiro <[hidden email]>:
>
>
> Well, in Windows and if you have the
> Windows Goodies
> package loaded you
>
> can do this:
>
>
> 'myAdobeDocument.pdf ' asFilename
> startAssociatedApplication
>
>
> I'm not sure if this start by associatiated file
> type thing was ever
>
> implemented for Linux and I doubt if it has been
> done across the board.
>
>
> -Charles
>
>
> On Thu, 02 Mar 2006 10:26:04 -0500, Rob Vens <
> [hidden email]> wrote:
>
>
> > I was under the impression that I could do the
> following:
>
> > ExternalProcess defaultClass cshOne: '"c:\Mijn
>
> > Projecten\Privé\Correspondentie\Postvak
> Uit\Brieven\Belastingdienst 11
>
> > oktober 1999.pdf"'
>
> > resulting in Acrobat starting up and
> showing the
> file.
>
> > However I tried and nothing happened.
> Is there a
> way to tell the os I
>
> > want
>
> > it to open a file?
>
>
>
>
> --
>
> Charles A. Monteiro
>
>
>
>
>
> --
> Alan Knight [|], Cincom Smalltalk Development
> [hidden email]
> [hidden email]
> http://www.cincom.com/smalltalk
>
> "The Static Typing Philosophy: Make it fast. Make it
> right. Make it
> run." - Niall Ross
>
>
>