source: cprs/branches/tmg-cprs/m_files/TMGKERNL.m@ 1039

Last change on this file since 1039 was 896, checked in by Kevin Toppenberg, 14 years ago

replacing soft links with actual files

File size: 22.7 KB
Line 
1TMGKERNL ;TMG/kst/OS Specific functions ;11/01/04
2 ;;1.0;TMG-LIB;**1**;04/24/09
3
4 ;"TMG KERNEL FUNCTIONS
5 ;"I.e. functions that are OS specific.
6 ;"Kevin Toppenberg MD
7 ;"GNU General Public License (GPL) applies
8 ;"7-12-2005
9
10 ;"=======================================================================
11 ;" API -- Public Functions.
12 ;"=======================================================================
13 ;"$$Dos2Unix^TMGKERNL(FullNamePath)
14 ;"$$IsDir^TMGKERNL(Path)
15 ;"$$Move^TMGKERNL(Source,Dest)
16 ;"$$Copy^TMGKERNL(Source,Dest)
17 ;"$$mkdir(Dir) -- provide a shell for the Linux command 'mkdir'
18 ;"$$rmdir(Dir) -- provide a shell for the Linux command 'rmdir'
19 ;"$$Convert^TMGKERNL(FPathName,NewType) -- convert a graphic image to new type
20 ;"$$XLTLANG(Phrase,langPair) -- execute a linux OS call to convert a phrase into another spoken language
21 ;"$$GetPckList(PckInit,Array,NeedsRefresh,PckDirFName) -- launch special linux script to get patch file list from ftp.va.gov
22 ;"$$DownloadFile^TMGKERNL(URL,DestDir) -- Interact with Linux to download a file with wget
23 ;"$$EditHFSFile^TMGKERNL(FilePathName) -- interact with Linux to edit a file on the host file system
24 ;"ZSAVE -- to save routine out to HFS
25 ;"MAKEBAKF^TMGKERNL(FilePathName,NodeDiv) ;Make Backup File if original exists
26 ;"IOCapON -- redirect IO to a HFS file, so that it can be captured.
27 ;"IOCapOFF(pOutArray) -- restore IO channel to that prior IOCapON was called, and return captured output in OutArray
28 ;"KillPID(JobNum) -- send message to MUPIP to kill Job
29 ;"MJOBS(array) -- execute a linux OS call to get list of all 'mumps' jobs using: 'ps -C mumps'
30 ;"$$GetScrnSize(ROWS,COLS) --query the OS and get the dimensions of the terminal window.
31
32 ;"=======================================================================
33 ;"Dependancies
34 ;"=======================================================================
35
36 ;"=======================================================================
37
38Dos2Unix(FullNamePath)
39 ;"Purpose: To execute the unix command Dos2Unix on filename path
40 ;"FullNamePath: The filename to act on.
41 ;"Result: 0 if no error; >0 if error
42 ;"Notice!!!! The return code here is DIFFERENT from usual
43
44 new result set result=0
45 if $get(FullNamePath)="" goto DUDone
46 new spec set spec(" ")="\ "
47 set FullNamePath=$$REPLACE^XLFSTR(FullNamePath,.spec)
48
49 new HookCmd set HookCmd="dos2unix -q "_FullNamePath
50 zsystem HookCmd
51 set result=$ZSYSTEM&255 ;"get result of execution. (low byte only)
52
53DUDone
54 quit result
55
56
57FileSize(FullNamePath)
58 ;"Purpose: To return the size of the file, in bytes.
59 ;"Input: FullNamePath: The filename to act on.
60 ;"Result: -1 if error, or returns size in bytes
61
62 new result set result=-1
63 new p set p="myTerm"
64 open p:(COMMAND="stat --format=%s "_FullNamePath:readonly)::"pipe"
65 use p
66 new x read x
67 close p use $p
68 ;"write "reply was :",x,!
69 if x'["cannot stat" set result=+x
70 quit result
71
72IsDir(Path,NodeDiv)
73 ;"Purpose: To determine if Path is a path to a directory (i.e. are there sub files)
74 ;"Input: Path to test, e.g. "/home/user" or "/home/user/"
75 ;" NodeDiv: [OPTIONAL] -- the character that separates folders (e.g. "/")
76 ;" if not supplied, then default value is "/"
77 ;"Result: 1 filepath is actually a directory
78 ;"Note: NEW! Will now return 1 if Path is a valid path to a directory, but there are no files in directory
79
80 set Path=$get(Path)
81 set NodeDiv=$get(NodeDiv,"/")
82 if $extract(Path,$length(Path))'=NodeDiv set Path=Path_NodeDiv
83
84 new p set p="myTerm"
85 open p:(COMMAND="stat --format=%F "_Path:readonly)::"pipe"
86 use p
87 new x read x
88 close p use $p
89 quit (x="directory")
90
91 ;" ==== old code/method below (slower) ===
92 ;"Old results
93 ;"Result: 1 if there are files in path, 0 otherwise
94 ;"Note: if Path is a valid path to a directory, but there are no files in directory, 0 returned.
95
96 new TMGMask set TMGMask("*")=""
97 new TMGFiles
98 new result set result=0
99
100 new spec set spec(" ")="\ "
101 set Path=$$REPLACE^XLFSTR(Path,.spec)
102
103 ;"Note: I can't seem to get this to work with names containing spaces.
104 if $$LIST^%ZISH(Path,"TMGMask","TMGFiles")=1 do
105 . new index set index=$order(TMGFiles(""))
106 . if index'="" set result=1
107
108 quit result
109
110
111Move(Source,Dest)
112 ;"Purpose to provide a shell for the Linux command 'mv'
113 ;" This can serve to move or rename a file
114 ;"Note: a platform independant version of the this could be constructed later...
115 ;"Result: 0 if no error; >0 if error
116 ;"Notice!!!! The return code here is DIFFERENT from usual
117
118 new HookCmd,result
119 new Srch
120 set Srch(" ")="\ "
121 set Source=$$REPLACE^XLFSTR(Source,.Srch)
122 set Dest=$$REPLACE^XLFSTR(Dest,.Srch)
123 set HookCmd="mv "_Source_" "_Dest
124 zsystem HookCmd
125 set result=$ZSYSTEM&255 ;"get result of execution. (low byte only)
126 quit result
127
128
129Copy(Source,Dest)
130 ;"Purpose to provide a shell for the Linux command 'cp'
131 ;" This can serve to move or rename a file
132 ;"Note: a platform independant version of the this could be constructed later...
133 ;"Result: 0 if no error; >0 if error
134 ;"Notice!!!! The return code here is DIFFERENT from usual
135
136 new HookCmd,result
137 new Srch
138 set Srch(" ")="\ "
139 set Source=$$REPLACE^XLFSTR(Source,.Srch)
140 set Dest=$$REPLACE^XLFSTR(Dest,.Srch)
141 set HookCmd="cp "_Source_" "_Dest
142 zsystem HookCmd
143 set result=$ZSYSTEM&255 ;"get result of execution. (low byte only)
144 quit result
145
146mkdir(Dir)
147 ;"Purpose to provide a shell for the Linux command 'mkdir'
148 ;"Note: a platform independant version of the this could be constructed later...
149 ;"Result: 0 if no error; >0 if error
150 ;"Notice!!!! The return code here is DIFFERENT from usual
151
152 new HookCmd,result
153 new Srch set Srch(" ")="\ "
154 set Dir=$$REPLACE^XLFSTR(Dir,.Srch)
155 set HookCmd="mkdir "_Dir
156 zsystem HookCmd
157 set result=$ZSYSTEM&255 ;"get result of execution. (low byte only)
158 quit result
159
160rmdir(Dir)
161 ;"Purpose to provide a shell for the Linux command 'rmdir'
162 ;"Note: a platform independant version of the this could be constructed later...
163 ;"Result: 0 if no error; >0 if error
164 ;"Notice!!!! The return code here is DIFFERENT from usual
165
166 new HookCmd,result
167 new Srch set Srch(" ")="\ "
168 set Dir=$$REPLACE^XLFSTR(Dir,.Srch)
169 set HookCmd="rmdir "_Dir
170 zsystem HookCmd
171 set result=$ZSYSTEM&255 ;"get result of execution. (low byte only)
172 quit result
173
174
175Convert(FPathName,NewType)
176 ;"Purpose: to convert a graphic image on the linux host to new type
177 ;" i.e. image.jpg --> image.png. This is more than a simple renaming.
178 ;"Input: FPathName -- full path, filename and extention. E.g. "\tmp\image.jpg"
179 ;" NewType -- the new image type (without '.'),
180 ;" E.g. "jpg", or "JPG", or "TIFF", or "pcd" (NOT ".jpg" etc)
181 ;"Output: New FPathName (with new extension) to new image file, or "" if problem
182 ;"
183 ;"Note: If the conversion is successful, then the original image will be deleted
184 ;"Note: This function depends on the ImageMagick graphic utility "convert" to be
185 ;" installed on the host linux system, and in the path so that it can be
186 ;" launched from any directory.
187
188 new newFPathName set newFPathName=""
189 set NewType=$get(NewType)
190 if NewType="" goto ConvDone
191
192 new FName,FPath,FileSpec
193 do SplitFNamePath^TMGIOUTL(FPathName,.FPath,.FName,"/")
194 set FileSpec(FName)=""
195
196 set newFPathName=$piece(FPathName,".",1)_"."_NewType
197
198 ;"Setup and launch linux command to execute convert
199 new CmdStr
200 set CmdStr="convert "_FPathName_" "_newFPathName
201 do
202 . ;"new $ETRAP,$ZTRAP
203 . ;"set $ETRAP="S $ECODE="""""
204 . zsystem CmdStr ;"Launch command
205
206 ;"get result of execution. (low byte only) -- if wanted
207 new CmdResult set CmdResult=$ZSYSTEM&255
208 if CmdResult'=0 do goto ConvDone
209 . set newFPathName=""
210
211 ;"Delete old image file
212 ;"**** temp!!!!! REMOVE COMMENTS LATER
213 ;"new temp set temp=$$DEL^%ZISH(FPath,"FileSpec")
214
215ConvDone
216 quit newFPathName
217
218
219XLTLANG(Phrase,langPair)
220 ;"Purpose: To execute a linux OS call to convert a phrase into another
221 ;" spoken language
222 ;"Input: Phrase -- The text to be translated.
223 ;" LangPair -- a language pair (as allowed by Google translater)
224 ;" for now, tested pairs are:
225 ;" "en-es" -- english -> spanish
226 ;" "en-fr" -- english --> french
227 ;" "en-da" -- english --> ?
228 ;"Result: The translated text, or "" if error.
229 ;"Note: This depends on the "tw" package be installed in the host OS
230 ;" I got this on 7/11/08 from: http://savannah.nongnu.org/projects/twandgtw/
231 ;"Note: This is not working for some reason.....
232
233 new result set result=""
234 set langPair=$get(langPair,"en-es")
235 set Phrase=$get(Phrase,"?? Nothing Provided ??")
236
237 new msgFName set msgFName=$$UNIQUE^%ZISUTL("/tmp/TransLang.txt")
238
239 ;"Setup and launch linux command to execute tw command
240 new CmdStr
241 set CmdStr="tw translate.google.com."_langPair_" """_Phrase_""" > """_msgFName_""""
242
243 ;"write "About to execute zsystem command:",!,CmdStr,!
244 zsystem CmdStr ;"Launch command in linux OS
245 ;"write "Back from zsystem",!
246
247 ;"get result of execution. (low byte only) -- if wanted
248 new CmdResult set CmdResult=$ZSYSTEM&255
249 if CmdResult'=0 goto TLDone
250
251 new FName,FPath
252 do SplitFNamePath^TMGIOUTL(msgFName,.FPath,.FName,"/")
253 new resultArray
254 if $$FTG^%ZISH(FPath,FName,"resultArray(0)",1)=0 goto TLDone
255 set result=$get(resultArray(0))
256
257TLDone
258 quit result
259
260
261TestTrans
262 set langPair=$get(langPair,"en-es")
263 set Phrase=$get(Phrase,"Hello friend")
264 new msgFName set msgFName=$$UNIQUE^%ZISUTL("/tmp/TransLang.txt")
265
266 new CmdStr
267 new qtChar set qtChar="'"
268
269 set CmdStr="sh /var/local/OpenVistA_UserData/twlang.sh "_qtChar_langPair_qtChar_" "_qtChar_Phrase_qtChar_" "_msgFName
270 write "About to execute zsystem command:",!,CmdStr,!
271 zsystem CmdStr ;"Launch command in linux OS
272 write "Back from zsystem",!
273
274 set qtChar=""""
275 set CmdStr="sh /var/local/OpenVistA_UserData/twlang.sh "_qtChar_langPair_qtChar_" "_qtChar_Phrase_qtChar_" "_msgFName
276 write "About to execute zsystem command:",!,CmdStr,!
277 zsystem CmdStr ;"Launch command in linux OS
278 write "Back from zsystem",!
279
280 quit
281
282
283GetPckList(PckInit,Array,NeedsRefresh,PckDirFName)
284 ;"Purpose: Call Linux, launching special script to get patch file list from ftp.va.gov
285 ;" This is a support function for automating the KIDS installation of patches.
286 ;"Input: PckInit -- this is the namespace of the package to get patches for, e.g. 'DI' for fileman
287 ;" Array -- PASS BY REFERENCE. An OUT parameter. Format:
288 ;" Array(0)=1st line
289 ;" Array(1)=2nd line etc.
290 ;" NeedsRefresh -- if 0 then no refresh needed, just set PckDirFName (but ensure file exists)
291 ;" PckDirFName -- Optional. PASS BY REFERNCE, an OUT PARAMETER. Filled with HFS filename of file
292 ;"Result : 1=success, 0=failure
293
294 new result set result=1 ;"success
295 kill Array
296 if $get(PckInit)="" set result=0 goto GPLDone
297
298 ;"Results will be stored in /<dir>/ftp.va.gov-dirFor-'PckInit'
299 new FName,FPath
300 ;"Fix this.... check if path exists.....
301 set FPath=$get(^TMG("KIDS","PATCH DIR"))
302 if (FPath="")!($$IsDir^TMGKERNL(FPath)=0) do
303 . new Msg set Msg="Please choose a file path for storing VA patches in."
304 . set FPath=$$GetDirName^TMGIOUTL2(Msg,DefPath,"/","Pick directory")
305 if FPath="" set result=0 goto GPLDone
306 set FName="ftp.va.gov-dirFor-"_PckInit
307 set PckDirFName=FPath_FName
308 if ($get(NeedsRefresh)'>0)&($$FileExists^TMGIOUTL(PckDirFName)) goto GPLDone
309
310 new FPScript set FPScript=$get(^TMG("KIDS","VA FTP Script"))
311 if (FPScript'=""),($$FileExists^TMGIOUTL(FPScript)=0) do
312 . kill ^TMG("KIDS","VA FTP Script")
313 . set FPScript=""
314 if FPScript="" do
315 . new msg set msg="Linux script needed: vaftp_launcher.sh\n"
316 . set msg=msg_"Please browse to this script and select it after the pause."
317 . set FPScript=$$GetFName^TMGIOUTL(msg,"/","vaftp_launcher.sh")
318 . if $$FileExists^TMGIOUTL(FPScript) do
319 . . set ^TMG("KIDS","VA FTP Script")=FPScript
320 . else do
321 . . write "ERROR: Choice of "_FPScript_" is invalid. Aborting."
322 . . set FPScript=""
323 if FPScript="" set result=0 goto GPLDone
324
325 new CmdStr set CmdStr=FPScript_" "_PckInit_" "_FPath
326 zsystem CmdStr ;"Launch command in linux OS
327
328 ;"get result of execution. (low byte only) -- if wanted
329 new CmdResult set CmdResult=$ZSYSTEM&255
330 if CmdResult'=0 do
331 . ;"Failed, so get log file instead of results
332 . set FName="ftp.va.gov_log"
333 . set result=1 ;"success
334
335GPL2 ;"Get results file (or log file if problem)
336 if $$FTG^%ZISH(FPath,FName,"Array(0)",1)=0 set result=0 goto GPLDone
337
338GPLDone
339 quit result
340
341
342DownloadFile(URL,DestDir,Verbose)
343 ;"Purpose: Interact with Linux to download a file with wget
344 ;"Input: URL -- this is the URL of the file to be downloaded, as to be passed to wget
345 ;" if the server is an FTP server, then URL should start with 'ftp://'
346 ;" NOTE: the URL will be enclosed in " ", so it may contain spaces etc,
347 ;" but should NOT have escaped characters, i.e. "Not\ this"
348 ;" Exception "April Fool'\''s Day" is proper
349 ;" DestDir -- this is the destination directory, on the HFS, where file should be stored
350 ;" Verbose -- OPTIONAL. If 1, then output from wget is shown. Default is 0
351 ;"result: 1 if success, 0 if failure
352
353 ;"NOTE: This needs to be rewritten to use the vawget_launcher because wget it
354 ;" hanging when the file doesn't exist, and the process has to be aborted...
355
356 new CmdStr,qFlag
357 ;"Setup and launch linux command to execute command
358 if +$get(Verbose) set qFlag=""
359 else set qFlag="-q "
360 set CmdStr="wget "_qFlag_"-P """_DestDir_""" """_URL_""""
361 zsystem CmdStr ;"Launch command in linux OS
362
363 ;"get result of execution. (low byte only)
364 new CmdResult set CmdResult=$ZSYSTEM&255
365 new result set result=(CmdResult=0)
366
367 quit result
368
369
370EditHFSFile(FilePathName)
371 ;"Purpose: interact with Linux to edit a file on the host file system
372 ;"Input: FilePathName -- the full path of the file to edit.
373 ;"result: 1 if success, 0 if failure
374
375 ;"Setup and launch linux command to execute command
376 new CmdStr set CmdStr="nano "_FilePathName
377 zsystem CmdStr ;"Launch command in linux OS
378
379 ;"get result of execution. (low byte only)
380 new CmdResult set CmdResult=$ZSYSTEM&255
381 new result set result=(CmdResult=0)
382 quit result
383
384
385ZSAVE
386 ;"Purpose: to save routine out to HFS
387 ;"Input: globally scoped variable X should hold routine name
388
389 ;"NOTE: this was moved out of ^DD("OS",19,"ZS")
390 ;"Original line there was (all three lines were one long line)
391 ;"N %I,%F,%S S %I=$I,%F=$P($P($ZRO,")"),"(",2)_"/"_X_".m" O %F:(NEWVERSION)
392 ;"U %F X "S %S=0 F S %S=$O(^UTILITY($J,0,%S)) Q:%S="""" Q:'$D(^(%S)) S %=
393 ;"^UTILITY($J,0,%S) I $E(%)'="";"" W %,!" C %F U %I
394
395 ;"NOTE: The KIDS system seems to be using X ^%ZOSF("SAVE") instead of this.
396
397 new %I,%F,%S
398 new % ;"//kt added -- not newing this caused problems in SAVE^DIKZ
399 set %I=$I
400 new %DIR set %DIR=$P($P($ZRO,")"),"(",2)
401 set %DIR=$piece(%DIR," ",$length(%DIR," "))
402 set %F=%DIR_"/"_X_".m"
403 open %F:(NEWVERSION)
404 use %F
405 set %S=0
406 for set %S=$O(^UTILITY($J,0,%S)) Q:%S="" Q:'$D(^(%S)) do
407 . set %=^UTILITY($J,0,%S)
408 . if $E(%)'=";" W %,!
409 close %F
410 use %I
411
412 quit
413
414
415MAKEBAKF(FilePathName,NodeDiv) ;"Make Backup File if original exists
416 ;"Purpose: to COPY existing File to File-ext_#.bak, creating a backup
417 ;" e.g. /tmp/dir1/FName.txt --> /tmp/dir1/FName-txt_1.bak
418 ;"Input: FilePathName -- the name, e.g. /tmp/dir1/filename.txt
419 ;" NodeDiv -- OPTIONAL. Default is "/"
420 ;" The node divider. "/" for unix, "\" for Microsoft
421 ;"results: none
422 ;"Note: This assumes that the HFS supports filenames like FName-txt_1.bak,
423 ;" and length file name is not limited (e.g. not old 8.3 DOS style)
424 ;" Also, if backup file, then number is incremented until a filename is found that doesn't exists
425 ;" e.g. /tmp/dir1/FName-txt_1.bak
426 ;" /tmp/dir1/FName-txt_2.bak
427 ;" /tmp/dir1/FName-txt_3.bak
428
429 set NodeDiv=$get(NodeDiv,"/")
430 if $$FileExists^TMGIOUTL(FilePathName) do ;"backup file if it exists
431 . new count set count=0
432 . new FName,FPath,done
433 . do SplitFNamePath^TMGIOUTL(FilePathName,.FPath,.FName,NodeDiv)
434 . for do quit:done
435 . . set count=count+1
436 . . new bakName set bakName=FName_"_"_count
437 . . set bakName=FPath_$translate(bakName,".","-")_".bak"
438 . . if $$FileExists^TMGIOUTL(bakName) set done=0 quit
439 . . else do
440 . . . set done=1
441 . . . if $$Copy(FilePathName,bakName)
442
443 quit
444
445IOCapON
446 ;"Purpose: to redirect IO to a HFS file, so that it can be captured.
447 ;"NOTE: CAUTION: If this is called, and then a routine asks for user input,
448 ;" then the program will appear to hang, because the message asking
449 ;" for input has gone to the output channel.
450
451 set TMGIOCAP=IO
452 set TMGIOCPT="/tmp/"
453 set TMGIOCFN="io-capture-"_$J_".txt"
454 set IO=TMGIOCPT_TMGIOCFN
455 open IO:(REWIND)
456 use IO
457
458 quit
459
460
461IOCapOFF(pOutArray)
462 ;"Purpose: To restore IO channel to that prior IOCapON was called, and return
463 ;" captured output in OutArray
464 ;"NOTE: MUST call IOCapON prior to calling this function
465 ;"Input: Globally-scoped TMGIOCAP is used.
466 ;" pOutArray -- PASS BY NAME, an OUT PARAMETER. Prior contents are killed.
467 ;"results: none
468
469 close IO
470 if $get(TMGIOCAP)="" use $P goto IOCDone
471 set IO=TMGIOCAP
472 use IO
473 if $get(pOutArray)="" goto IOCDone
474 kill @pOutArray
475
476 if ($get(TMGIOCPT)="")!($get(TMGIOCFN)="") goto IOCDone
477 if $$FTG^%ZISH(TMGIOCPT,TMGIOCFN,$name(@pOutArray@(0)),1)
478 new TMGA set TMGA(TMGIOCFN)=""
479 if $$DEL^%ZISH(TMGIOCPT,"TMGA")
480
481IOCDone quit
482
483KillPID(JobNum)
484 ;"Purpose: send message to MUPIP to kill Job
485 new CmdStr set CmdStr="mupip stop "_JobNum
486 zsystem CmdStr ;"Launch command in linux OS
487 ;"do PressToCont^TMGUSRIF
488 quit
489
490TEST
491 new array
492 new p set p="temp"
493 open p:(COMMAND="ps -C mumps":readonly)::"pipe"
494 use p
495 new lineIn
496 for do quit:($zeof)
497 . read lineIn
498 . new ch for do quit:(ch'=" ")
499 . . set ch=$extract(lineIn,1,1)
500 . . if ch=" " set lineIn=$extract(lineIn,2,40)
501 . if +lineIn=0 quit
502 . set array(+lineIn)=lineIn
503 close p
504 use $p
505 zwr array
506 quit
507
508MJOBS(array)
509 ;"Purpose: To execute a linux OS call to get list of all 'mumps' jobs
510 ;" using: 'ps -C mumps'
511 ;"Input: array -- PASS BY REFERNCE, an OUT PARAMETER.
512 ;"Output: array is filled as follows: (Prior data is killed)
513 ;" array(job#)=InfoLineFromOS
514 ;" array(job#)=InfoLineFromOS
515 ;" e.g. array(4483)=' 4883 pts/8 00:00:00 mumps'
516 ;" e.g. array(19308)='19308 ? 00:00:00 mumps'
517 ;" e.g. array(27454)='27454 pts/5 00:00:53 mumps'
518 ;"Result: none
519
520 new p set p="temp"
521 open p:(COMMAND="ps -C mumps":readonly)::"pipe"
522 use p
523 new lineIn,ch
524 for do quit:($zeof)
525 . read lineIn
526 . for do quit:(ch'=" ")
527 . . set ch=$extract(lineIn,1,1) quit:(ch'=" ")
528 . . set lineIn=$extract(lineIn,2,40)
529 . if +lineIn=0 quit
530 . set array(+lineIn)=lineIn
531 close p
532 use $p
533 quit
534
535 ;"====== old method below ==============
536 kill array
537 new msgFName set msgFName=$$UNIQUE^%ZISUTL("/tmp/mjobslist.txt")
538 new CmdStr set CmdStr="ps -C mumps > """_msgFName_""""
539 zsystem CmdStr ;"Launch command in linux OS
540 ;
541 ;"get result of execution. (low byte only) -- if wanted
542 new CmdResult set CmdResult=$ZSYSTEM&255
543 if CmdResult'=0 goto MJDone
544 ;
545 new FName,FPath
546 do SplitFNamePath^TMGIOUTL(msgFName,.FPath,.FName,"/")
547 new resultArray
548 if $$FTG^%ZISH(FPath,FName,"resultArray(0)",1)=0 goto TLDone
549 ;
550 ;"Delete temp info file
551 new FileSpec set FileSpec(FName)=""
552 new temp set temp=$$DEL^%ZISH(FPath,"FileSpec")
553 ;
554 ;"Format resulting array
555 new i set i=0
556 for set i=$order(resultArray(i)) quit:(i'>0) do
557 . new j set j=$extract(resultArray(i),1,5)
558 . new ch for do quit:(ch'=" ")
559 . . set ch=$extract(j,1,1)
560 . . if ch=" " set j=$extract(j,2,40)
561 . set array(+j)=resultArray(i)
562 ;
563MJDone quit
564
565
566GetScrnSize(ROWS,COLS)
567 ;"Purpose: To query the OS and get the dimensions of the terminal window
568 ;"Input: ROWS,COLS -- Optional. PASS BY REFERENCE. Filled with results
569 ;"Results: Row^Col e.g. '24^80', or '24^60' as a default if problem.
570 ;"Note: thanks Bhaskar for figuring this out!
571 new p set p="myTerm"
572 open p:(COMMAND="stty -a -F "_$p_"|grep columns":readonly)::"pipe"
573 ;"open p:(COMMAND="stty -a |grep columns":readonly)::"pipe"
574 new x
575 for use p read x quit:($zeof)!(x["columns")
576 close p use $p
577 set COLS=+$piece(x,"columns ",2)
578 set ROWS=+$piece(x,"rows ",2)
579 if (COLS=0)&(ROWS=0) do
580 . set COLS=60,ROWS=24
581 quit ROWS_"^"_COLS
Note: See TracBrowser for help on using the repository browser.