本帖最后由 pcl_test 于 2015-10-25 12:36 编辑
采用的清屏+注释屏蔽法,混编及传值方式与bat&js混编类同,类似的需注意批处理代码中包含 ''' 字符的问题- @echo off
- set "str=hello world"
- for /f "delims=" %%a in ('python -c "print('%str%'.upper())"') do echo;%%a
- pause
复制代码
- @echo off
- (for /l %%a in (1 1 5) do @echo;%%a)|python -c "import sys;print(sys.stdin.read().replace('3','hi'))"
- pause
复制代码
- #coding: gbk
- '''*&cls
- @echo off
- set "str=哈"
- python "%~f0" "%str%"
- pause&exit
- '''
- import sys
- print(sys.argv[1]*10);
复制代码
- '''*&cls
- @echo off
- >"%tmp%\a.txt" (for /l %%a in (1 1 5) do @set /p=%%a)<nul
- python "%~f0"<"%tmp%\a.txt">"%tmp%\b.txt"
- start "" "%tmp%\b.txt"
- pause&exit
- '''
- import sys;
- line=list(sys.stdin.readline());
- print(''.join([str(int(x)+1) for x in line]));
复制代码
- #*&cls&wmic LogicalDisk where "DriveType='3'" get Caption,FreeSpace|python "%~f0"&pause&exit
- import sys;
- n=0;
- while True:
- line=sys.stdin.readline().replace('\r\n','');
- if not line:
- break;
- if n==1:
- ar=line.split();
- print(ar[0]+'\t'+str(long(ar[1])/1073741824)+'GB');
- else:
- print(line);
- n+=1;
复制代码
|