Hello Guest it is July 18, 2025, 05:35:04 PM

Author Topic: I can't open a pdf file from a screen script  (Read 9234 times)

0 Members and 1 Guest are viewing this topic.

I can't open a pdf file from a screen script
« on: July 12, 2024, 01:12:08 AM »
I have been trying to implement a simple help button on my screen that opens a pdf file.

I have tried both wx.wxExecute() and os.execute().

I can open a file explorer, or notepad with this in a screen script:  wx.wxExecute("notepad.exe")
 
But when I just try to open a pdf file this way:   
wx.wxExecute("C:\\Mach4Hobby\\Modules\\JNWDWKS\\Docs\\ProbeCenter_User_Manual.pdf")

It just gives me the attached pop saying it executed successfully, but nothing actually opens.

I've tried adding a start command, and I've also tried the lua os.execute() command and it does basically the same thing.

I get the same results from the screenload script, the button script, and a module.

I saw a thread on here from 2019 where a guy was having the same exact problem, but there wasn't any resolution.

Does anyone have a hint for me that I could try?

thanks,
jim

Offline Graham Waterworth

*
  • *
  •  2,783 2,783
  • Yorkshire Dales, England
Re: I can't open a pdf file from a screen script
« Reply #1 on: July 12, 2024, 07:56:33 AM »
Have you tried it this way

wx.wxExecute(C:.....AcroRd32.EXE /C:\\Mach4Hobby\\Modules\\JNWDWKS\\Docs\\ProbeCenter_User_Manual.pdf)

Without engineers the world stops
Re: I can't open a pdf file from a screen script
« Reply #2 on: July 12, 2024, 01:12:25 PM »
I had not because I was hoping to run whatever the default program for pdfs was so it would be more portable.

However, that was a good idea because I just ran it that way and it works, so I know it not some kind of environmental probelm with Mach4 and Adobe reader.

I have tried the start command with it too, and its just like it won't run the default app association like it will in a windows shell.
Re: I can't open a pdf file from a screen script
« Reply #3 on: July 12, 2024, 01:52:03 PM »
Ok, since it seemed like this was some kind of command formatting problem, I went back and had a couple rounds with ChatGPT again.

It is amazing how well that thing works as long as you give very descriptive questions, and then follow up with descriptive results of how it did not work.
ChatGPT says the lua os.execute is a more straightforward way to execute a shell command, and it was right.


This code works, and will work from a module as well.

function ProbeCenter.OpenHelpFile(Mach4filepath)
    local inst = mc.mcGetInstance()
    local dir = mc.mcCntlGetMachDir(inst);
    local file_path = dir .. Mach4filepath
    local command = string.format('start "" "%s"', file_path)
    os.execute(command)
end