CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
When calling notepad..

 



KingNothing
Novice

Oct 4, 2011, 6:02 PM

Post #1 of 9 (1677 views)
When calling notepad.. Can't Post

Hi all to the forum,
here is my problem, i have write a program with gui (using Tk) and put a button that calls notepad and the file that i want to open.
Something like this, system('notepad file.txt')
That worked good in my tests when writing the code. But when i tried to make the .pl file executable via PerlApp I noticed that when i run the exe and click on the button to open the notepad the system freezes and i have to call the task manager. That happened both on windows xp and 7. To say the truth, i checked on the features "Hide console" on the perlapp before i make the file executable. When i uncheck this feature everything works great. But i dont want to have the console window at all when runnig my program. Does anyone know what elese can i do to solve this problem?
Thanks in advance.
I dont know if i posted in the right section, if not one moderator could remove it to one better.Smile


(This post was edited by KingNothing on Oct 4, 2011, 6:02 PM)


wickedxter
User

Oct 5, 2011, 9:35 AM

Post #2 of 9 (1641 views)
Re: [KingNothing] When calling notepad.. [In reply to] Can't Post

try a different program to compile your script... i've used
http://www.cava.co.uk/ its works great with TK


KingNothing
Novice

Oct 5, 2011, 9:54 AM

Post #3 of 9 (1640 views)
Re: [wickedxter] When calling notepad.. [In reply to] Can't Post

Hi, thanks for answering
i downloaded cava and made some of the steps.When i scan and build project then some files are created in the directory i have set. But i cant find the executable. Could you help me a little more please?
Edit: Actually i have found the executable and have set it to gui executable but when i double-click it nothing happens..Unsure


(This post was edited by KingNothing on Oct 5, 2011, 10:02 AM)


wickedxter
User

Oct 5, 2011, 4:00 PM

Post #4 of 9 (1633 views)
Re: [KingNothing] When calling notepad.. [In reply to] Can't Post

after scaning your script make sure the TK module is being found if not your have to add its directory to its search path...

to add it on the menu on the left side under the cava packager your project name will be their if you click it it will load tabs to the right click the tab labeled perl inter. and add the directory to tk
not d:/dir/to/tk just d:/dir/to because tk has a lot of modules and most are in their own directory outside of the tk folder...


KingNothing
Novice

Oct 6, 2011, 12:01 PM

Post #5 of 9 (1583 views)
Re: [wickedxter] When calling notepad.. [In reply to] Can't Post

I managed to do it following your steps but i have the same problem when i click on the button to open notepad, it freezes..Is there any other way to open a text file via notepad without the system("notepad file.txt") line maybe?


FishMonger
Veteran / Moderator

Oct 6, 2011, 4:24 PM

Post #6 of 9 (1577 views)
Re: [KingNothing] When calling notepad.. [In reply to] Can't Post

The system command will block the gui until you close notepad.

Use the Win32::Process module to create a detached process.
http://search.cpan.org/~jdb/Win32-Process-0.14/Process.pm


KingNothing
Novice

Oct 7, 2011, 1:34 AM

Post #7 of 9 (1536 views)
Re: [FishMonger] When calling notepad.. [In reply to] Can't Post

Yes i have noticed that! I have two files, the main one and the the other with the functions. In the main i wrote

Code
use Win32::Process; 
use Win32;

and i put the subroutine in the fun.pm file. But when i click to the button to open the file i get this one:
The filename, directory name, or volume label syntax is incorrect.
Tk::Error: 1 at Fun.pm line 1192.
Tk callback for .button1
Tk::__ANON__ at C:/strawberry/perl/site/lib/Tk.pm line 250
Tk::Button::butUp at C:/strawberry/perl/site/lib/Tk/Button.pm line 175
<ButtonRelease-1>
(command bound to event)

I have changed the directory to C:\Windows\System32\notepad.exe but i get the same error. Also, after that i have "notepad file.txt" and the file.txt does exist in the win32 dir. Any help would be really appreciated Smile


KingNothing
Novice

Oct 7, 2011, 3:56 AM

Post #8 of 9 (1532 views)
Re: [KingNothing] When calling notepad.. [In reply to] Can't Post

I finally did it Smile

Code
my $ProcessObj; 
Win32::Process::Create( $ProcessObj,
'C:\Windows\System32\notepad.exe',
'notepad C:\progr\file.txt',
0,
NORMAL_PRIORITY_CLASS,
'C:\progr',
) or die ErrorReport();

The final thing i have to do is to know where the file.txt is so to open it. Suppose my program first creates the file.txt and then the user can open it from the button choice. But, i cant put in the code the absolute path because, for me ok it works fine, but if someone download the program to \Downloads i want the file to be created there (i have done that) and to open that file in that specific dir. Any ideas guys?


KingNothing
Novice

Oct 7, 2011, 5:44 AM

Post #9 of 9 (1508 views)
Re: [KingNothing] When calling notepad.. [In reply to] Can't Post

Ok i finally finished it using Cwd.
Now it works just fine.
Thanks everyone for showing interest and answering my questions! Wink

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives