domvargas
12th June 2003, 20:39
Hi everybody!
I'm using the app_status function to verify the status of Excel.
My problem is: In some PCs, the path of Excel is different than the path showed in the code below. The function should be able to deal with this situation, but it doesn't works. Only in debug mode the mess "tcmels0006.o" appears. What's happen?
My Baan Code:
appl = "Program Files\Microsoft Office\Office\excel.exe"
start = appl & " " & local.filename
app_id = app_start(start,"","","","")
ret = app_status(app_id)
if ret = 0 then
mess("tcmels0006.o", 1, file.csv)
endif
Thanks!
Dom Vargas
lbencic
12th June 2003, 21:19
So, in debug, it's app_status check is coming up with 0 when the excel call fails, and not in debug you don't see the message?
Are you in some type of mode that prohibits display of the message - job.mode or api.mode maybe...?
Also, you can directly check the return value of the app_start command - if it is negative it was not successful.
NPRao
12th June 2003, 22:48
DomVargas,
My problem is: In some PCs, the path of Excel is different than the path showed in the code below. The function should be able to deal with this situation, but it doesn't works.
HINT:You have to use the DOS command - ftype to get the excel.exe file path on the computer.
Displays or modifies file types used in file extension associations
FTYPE [fileType[=[openCommandString]]]
fileType Specifies the file type to examine or change
openCommandString Specifies the open command to use when launching files
of this type.
Type FTYPE without parameters to display the current file types that
have open command strings defined. FTYPE is invoked with just a file
type, it displays the current open command string for that file type.
Specify nothing for the open command string and the FTYPE command will
delete the open command string for the file type. Within an open
command string %0 or %1 are substituted with the file name being
launched through the assocation. %* gets all the parameters and %2
gets the 1st parameter, %3 the second, etc. %~n gets all the remaining
parameters starting with the nth parameter, where n may be between 2 and 9,
inclusive. For example:
ASSOC .pl=PerlScript
FTYPE PerlScript=perl.exe %1 %*
would allow you to invoke a Perl script as follows:
script.pl 1 2 3
If you want to eliminate the need to type the extensions, then do the following:
set PATHEXT=.pl;%PATHEXT%
and the script could be invoked as follows:
script 1 2 3
Only in debug mode the mess "tcmels0006.o" appears. What's happen?
I found a bit different behaviour when I built our Excel Interface with app_start() in normal and debug mode. I think in Debug mode the Excel application is start was a parent-child (dependent) process and in normal mode the application was started as indepedent/spin-off from the original process.
lbencic
12th June 2003, 22:57
Along those lines, if you just send it the file with the .xls extension, it will call excel automatically, and you do not need to know the path or use fstat at all. ex:
app_start("C:\TEMP\HazMat1.xls", "", "", "","")
will directly start exel using theh HazMat1 file as input, just like double clicking on the file would in the windows environment.
bdittmar
13th June 2003, 10:31
Originally posted by domvargas
Hi everybody!
I'm using the app_status function to verify the status of Excel.
My problem is: In some PCs, the path of Excel is different than the path showed in the code below. The function should be able to deal with this situation, but it doesn't works. Only in debug mode the mess "tcmels0006.o" appears. What's happen?
My Baan Code:
appl = "Program Files\Microsoft Office\Office\excel.exe"
start = appl & " " & local.filename
app_id = app_start(start,"","","","")
ret = app_status(app_id)
if ret = 0 then
mess("tcmels0006.o", 1, file.csv)
endif
Thanks!
Dom Vargas
Hello,
For Excel and Word use the Registry of the client PC to determine path to the Application.
Like:
app_id=app_start("WINWORD.EXE path to document"&file, , , ,)
domvargas
13th June 2003, 18:42
Friends,
The file that I want to start is a CSV file.
I tried all sugestions without success except the Dos command Ftype, because I didn't found the command in my Dos system.
Any other sugestion, please?
I forgot mention that I'm using the BAANXL solution presented by Mr. Vamsi Potluru in this forum.
Thanks for the help.
Dom Vargas
lbencic
13th June 2003, 18:58
So..you tried using the
app_id=app_start("EXCEL.EXE path to document"&file.csv, , , ,)
If they have excel defined in the path, then it should come up... no?
Also, csv is a Excel extension as well, I have not tried, but I would think
app_id=app_start("c:\TEMP\file.csv", , , ,)
would also work.
mark_h
13th June 2003, 19:35
Yes a csv file should launch excel, but csv extension must be associated with excel. From just glancing at ~Vamsis' code it looks like it launches the .csv file. A test would be to just use windows explorer, double click a csv file and see if excel launches. If not associate it with excel.
Mark
NPRao
13th June 2003, 20:40
DomVargas,
I tried all sugestions without success except the Dos command Ftype, because I didn't found the command in my Dos system.
I see you are on Windows-NT. So click Start -> Run -> cmd. This takes you to the DOS command prompt.
Type in the command ftype > np, (or any file name) then view the file contents with notepad, or type command you can see the list of all the file extensions which can be handled by different applications.
This is how Windows opens a specific file with a known extension mapping to a application. This is what Lisa and Mark are typing to explain to you.
Here is a sample output-
AVIFile="C:\Program Files\Windows Media Player\wmplayer.exe" /Open "%L"
batfile="%1" %*
BCD.Document=C:\PROGRA~1\Baan\EME\Program\Eme.exe /dde
BFD.Document=C:\PROGRA~1\Baan\EME\Program\Eme.exe /dde
BPD.Document=C:\PROGRA~1\Baan\EME\Program\Eme.exe /dde
BPE.Document=C:\PROGRA~1\Baan\PV\Program\pv.exe /dde
Briefcase=explorer.exe %1
Bwprint.Document=C:\PROGRA~1\baan\BAANWI~1\bin\bwprint.exe "%1"
BW_Configuration=C:\WINNT\Baan\bin\BECS.exe "%1"
BW_Link=C:\WINNT\Baan\bin\BECS.exe "%1"
clpfile=clipbrd.exe %1
cmdfile="%1" %*
CodeWarrior_c="C:\Program Files\Metrowerks\CodeWarrior\bin\IDE.EXE" "%1"
CodeWarrior_c++="C:\Program Files\Metrowerks\CodeWarrior\bin\IDE.EXE" "%1"
CodeWarrior_cc="C:\Program Files\Metrowerks\CodeWarrior\bin\IDE.EXE" "%1"
EnterpriseCS.Document=C:\Ecsnt\ECSGui\ECS.exe /dde
ERD.Document=C:\PROGRA~1\Baan\EME\Program\Eme.exe /dde
ESD.Document=C:\PROGRA~1\Baan\EME\Program\Eme.exe /dde
Excel.Addin="C:\Program Files\MSOffice2K\Office\EXCEL.EXE" /e
Excel.Backup="C:\Program Files\MSOffice2K\Office\EXCEL.EXE" /e
Excel.Chart=C:\PROGRA~1\MSOFFI~1\Office\EXCEL.EXE /e
Excel.Chart.8="C:\Program Files\MSOffice2K\Office\EXCEL.EXE" /e
Excel.CSV="C:\Program Files\MSOffice2K\Office\EXCEL.EXE" /e
Excel.DIF="C:\Program Files\MSOffice2K\Office\EXCEL.EXE" /e
Excel.Macrosheet="C:\Program Files\MSOffice2K\Office\EXCEL.EXE" /e
Excel.Sheet.8="C:\Program Files\MSOffice2K\Office\EXCEL.EXE" /e
Excel.SLK="C:\Program Files\MSOffice2K\Office\EXCEL.EXE" /e
Excel.Template="C:\Program Files\MSOffice2K\Office\EXCEL.EXE" /e
Excel.Workspace="C:\Program Files\MSOffice2K\Office\EXCEL.EXE" /e
Excel.XLL="C:\Program Files\MSOffice2K\Office\EXCEL.EXE" /e
Excelhtmlfile="C:\Program Files\MSOffice2K\Office\EXCEL.EXE"
Excelhtmltemplate="C:\Program Files\MSOffice2K\Office\EXCEL.EXE"
exefile="%1" %*
NPRao
13th June 2003, 22:57
Well, other option would be to use the DOS find/search files option to find where the Excel.EXE is located.
C:\>dir /?
Displays a list of files and subdirectories in a directory.
DIR [filename] [/A[[:]attributes]] [/B] [/C] [/L] [/N]
[/O[[:]sortorder]] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]
[drive:][path][filename]
Specifies drive, directory, and/or files to list.
/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files - Prefix meaning not
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the
default. Use /-C to disable display of separator.
/D Same as wide but files are list sorted by column.
/L Uses lowercase.
/N New long list format where filenames are on the far right.
/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date/time (oldest first)
G Group directories first - Prefix to reverse order
/P Pauses after each screenful of information.
/Q Display the owner of the file.
/S Displays files in specified directory and all subdirectories.
/T Controls which time field displayed or used for sorting
timefield C Creation
A Last Access
W Last Written
/W Uses wide list format.
/X This displays the short names generated for non-8dot3 file
names. The format is that of /N with the short name inserted
before the long name. If no short name is present, blanks are
displayed in its place.
/4 Displays four-digit years
Switches may be preset in the DIRCMD environment variable. Override
preset switches by prefixing any switch with - (hyphen)--for example, /-W.
For example-
C:\>dir C:\superusr.xls /s/b
C:\superusr.xls
C:\>dir C:\mixedmode.pdf /s/b
C:\BaanDocs\std-docs\mixedmode.pdf
C:\>dir C:\mixedmode.pdf /s/b > np
C:\>type np
C:\BaanDocs\std-docs\mixedmode.pdf
C:\>dir C:\excel.exe /s/b
C:\Program Files\MSOffice2K\Office\EXCEL.EXE
C:\>
domvargas
13th June 2003, 23:58
Mr. Rao,
Please, can you explain me how to use the dir command in a baan session (like retrive the string that contain the path)?
Thanks,
Dom Vargas
NPRao
14th June 2003, 00:06
Dom,
You have to use the same commands you were using -
app_start() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_client_file_access_app_start) and check its status to get to know if its has finished its execution - app_status() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_client_file_access_app_status).
You need to redirect the output of dir command to a temporary file, and then parse the file for the excel file path using - seq.open.local() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_client_file_access_seq_open_local) and seq.read.local() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_client_file_access_seq_read_local) functions.
Then use the app_start() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_client_file_access_app_start) again with excel application file path, and xls file to open it.
domvargas
16th June 2003, 22:31
Hello people!
Mr. Rao,
I wrote this code, but didn't work. The file "baanxl.txt" was created but empty. Please, what´s wrong?
|# Verify path...
app_id = app_start("dir c:\excel.exe /s/b","c:\","","baanxl.txt","")
ret = app_status(app_id)
if ret = 0 then
message("Error in Path!")
else
fp4 = seq.open.local("c:\baanxl.txt", "w",0)
seq.read.local(excel.path, excel.size, fp4)
|# Verify Excel...
start = excel.path & " " & local.filename
app_id = app_start(start,"","","","")
ret = app_status(app_id)
if ret = 0 then
message("Error in Excel!")
endif
endif
Thanks
Dom Vargas
NPRao
16th June 2003, 23:29
DomVargas,
You werent checking the application status properly.
Anyways, here is a sample code, I hope its useful for you and others.
As I have been suggesting I would prefer to use the ftype command than
DOS search option due to performance reasons.
function main()
{
long app.id, fp, size, app.stat
string comd(256), local.path(256), buffer(1024), fname(256)
local.path = "C:\tmp" & str$(utc.num())
comd = "cmd /c dir C:\excel.exe /s/b "
app.id = app_start(comd, "C:\", "", local.path, local.path)
app.stat = app_status(app.id)
while app.stat
suspend(60000)
|* wait 1 minute before checking the next time because file searching
|* on the C:\ hard disk takes a lot of time
app.stat = app_status(app.id)
endwhile
fp = seq.open.local(local.path, "r", 0)
if fp >= 0 then
e = seq.read.local(buffer, size, fp)
|* You can check the value of buffer in debugger with escape sequences
endif
seq.close.local(fp)
fname = creat.tmp.file$( bse.tmp.dir$() )
|* Send the client file to server so that all the escape sequences are removed
e = client2server(local.path, fname, 0, 0, 0)
remove.local.file(local.path)
fp = seq.open(fname, "r")
if fp < 0 then
mess("zmadms0036", 1, fname) |* File Opening Error: %1$s
else
e = seq.gets(buffer, 1024, fp)
e = seq.close(fp)
e = file.rm(fname)
endif
}
so buffer contains the Excel application file path.
mark_h
16th June 2003, 23:37
Dom Vargas,
Not sure if this helps but here are some examples from the code and utilities forum.
First Thread (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=513) and the second thread (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=590&perpage=15&pagenumber=1). Check the second thread out and download the code I posted - I think it was pdfvers31.zip. It contains a sample of launching word and excel. We also have different excel devices for the different sites, so that way we know where to launch excel from.
Hope this helps!
Mark
domvargas
17th June 2003, 20:29
Dear friends,
I'm sorry, but the problem now is:
- The DIR command doesn't make any effect. I'm testing in a PC user running W98 under NT 4.0. The temporary file created (local.path) keeps empty after the processing.
I did a small change in the code just for test, without success:
comd = "COMMAND /C dir c:\excel.exe /s/b "
Can you help me (again...)?
Thanks!
Dom Vargas