Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
techwiki:dos [2019/10/25 02:45]
ying [control panels and admin tools]
techwiki:dos [2020/02/27 19:37] (current)
ying [start a process]
Line 29: Line 29:
 </​code>​ </​code>​
  
-call python file with same name<​code dos>+**call python file with same name**<code dos>
 @echo off @echo off
 call python %~dp0%~n0.py call python %~dp0%~n0.py
 pause pause
 +</​code>​
 +
 +**call custom python to run python file with passing parameter (Basic version)**<​code dos SameNameAsPyFile.bat>​
 +set CustPython=D:​\Pipeline\App_Win\Python27x64\
 +%CustPython%python.exe %~dp0%~n0.py %1
 +pause
 +</​code>​
 +
 +<code python SameNameAsPyFile.py>​
 +import os,sys
 +input_count = len(sys.argv)
 +print('​Inputs Count: {0}'​.format(input_count))
 +if input_count>​1:​
 +    print('​Passing File Path: {0}'​.format(sys.argv[1]))
 +</​code>​
 +
 +**call custom python to run python file with passing parameter (Advanced version)**<​code dos SameNameAsPyFileAdvanced.bat>​
 +:: dont type out cmds in cmd window
 +@echo off
 +set CustPython=R:​\Pipeline\App_Win\Python27x64\
 +
 +:: Check for Python Installation
 +python --version 2>NUL
 +if errorlevel 1 goto NoPython
 +
 +::====== hasPython ======
 +call python.exe %~dp0%~n0.py %1 && goto done
 +goto console
 +
 +::====== noPython ======
 +:NoPython
 +IF EXIST %CustPython% (
 +  echo %CustPython%
 +  call %CustPython%python.exe %~dp0%~n0.py %1 && goto done
 +  goto console
 +) ELSE (
 +  echo Error^: Python not detected  ​
 +)
 +
 +:console
 +pause
 +:done
 +</​code>​
 +
 +<code python SameNameAsPyFileAdvanced.py>​
 +import os,sys
 +input_count = len(sys.argv)
 +print('​Inputs Count: {0}'​.format(input_count))
 +if input_count>​1:​
 +    print('​Passing File Path: {0}'​.format(sys.argv[1]))
 +    sys.exit(0) # 0: success, 1-127: bad error
 +else:
 +    print('​Error:​ No File Passing to Python'​)
 +    sys.exit(1)
 </​code>​ </​code>​
  
Line 82: Line 136:
  
  
 +**Outlook**
  
 +  * create a email with content python version (the main code block) <code python>
 +# rough support code for reference
 +config['​appPath'​]['​email'​] = [r'​C:​\Program Files\Microsoft Office\Office*\OUTLOOK.EXE'​]
 +
 +# main code
 +app = self.getOptionPath(config['​appPath'​],​ '​email'​) # the outlook app path
 +address_list = ['​test@test.com'​]
 +subject = 'Daily Feedback'​
 +text_list = ['line 1', 'line 2']
 +cmd = '"​{0}"​ /c ipm.note /m "​{1}&​subject={2}&​body={3}"'​.format(app,​ ';'​.join(address_list),​ subject, '​\n'​.join(text_list))
 +if os.path.isfile(app):​
 +    print(cmd)
 +    subprocess.Popen(cmd)
 +
 +# support function for reference
 +    def getOptionPath(self,​ dict, name, all=0):
 +        # updated: 2019.01.09
 +        if name not in dict.keys():​
 +            print('​Dict has no key: {0}'​.format(name))
 +            return
 +        option_list = []
 +        if not isinstance(dict[name],​ (list,​tuple)):​
 +            option_list = [ dict[name] ]
 +        else:
 +            option_list = dict[name]
 +        if all == 0:
 +            found = None
 +            for option in option_list:​
 +                if '​*'​ in option:
 +                    # wildchar search
 +                    import glob
 +                    sub_option_list = glob.glob(option)
 +                    if len(sub_option_list) > 0:
 +                        sorted_option_list = sorted(sub_option_list)
 +                        print('​Scaning options:​\n'​+'​\n'​.join(sorted_option_list))
 +                        found = sorted_option_list[-1]
 +                        break
 +                else:
 +                    if os.path.exists(option):​
 +                        found = option
 +                        break
 +            if found is not None:
 +                found = found.replace('​\\','/'​)
 +            print('​found:​ {0}'​.format(found))
 +            return found
 +        else:
 +            all_option = []
 +            for option in option_list:​
 +                if '​*'​ in option:
 +                    # wildchar search
 +                    import glob
 +                    sub_option_list = glob.glob(option)
 +                    all_option.extend(sorted(sub_option_list,​ reverse=1))
 +                else:
 +                    if os.path.exists(option):​
 +                        all_option.append(option)
 +            standard_path_option = []
 +            for each_path in all_option:
 +                standard_path = each_path.replace('​\\','/'​)
 +                if standard_path not in standard_path_option:​
 +                    standard_path_option.append(standard_path)
 +            print(standard_path_option)
 +            return standard_path_option
 +</​code>​
 +  * outlook attach file (/c imp.note need or not need?) <code dos>​outlook.exe /c ipm.note /a "​FileAttachPathName"​ /m "​email@addresses.com&​cc=&​subject=&​body="</​code>​
 +    * ref: https://​www.slipstick.com/​outlook/​how-to-use-outlooks-command-line-switches/​
 ===== system operation ===== ===== system operation =====