標準輸入輸出重定向
函式名:freopen 宣告:FILE *freopen( const char *path, const char *mode, FILE *stream ); 所在檔案: stdio.h 引數說明: path: 檔名,用於儲存輸入輸出的自定義檔名。 mode: 檔案開啟的模式。
DESCRIPTION The fopen() function opens the file whose name is the string pointed to by path and associates a stream with it. The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.): r Open text file for reading. The stream is positioned at the beginning of the file. r+ Open for reading and writing. The stream is positioned at the beginning of the file. w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file. a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file. stream: 一個檔案,通常使用標準流檔案,stdin, stdout, stderr。 返回值:成功,則返回一個path所指定檔案的指標;失敗,返回NULL。(一般可以不使用它的返回值) 功能:實現重定向,把預定義的標準流檔案定向到由path指定的檔案中。
標準流檔案具體是指stdin、stdout和stderr。其中stdin是標準輸入流,預設為鍵盤;stdout是標準輸出流,預設為螢幕;stderr是標準錯誤流,一般把螢幕設為預設。
例項:
python: 對print的輸出重定向:#include <stdio.h> int main() { int a,b; freopen("debug\\in.txt","r",stdin); //輸入重定向,輸入資料將從in.txt檔案中讀取 freopen("debug\\out.txt","w",stdout); //輸出重定向,輸出資料將儲存在out.txt檔案中 while(scanf("%d %d",&a,&b)!=EOF) printf("%d\n",a+b); fclose(stdin);//關閉檔案 fclose(stdout);//關閉檔案 freopen("dev/console", "w", stdout); //重新開啟輸出到螢幕,linux平臺 freopen("dev/console", "r", stdin); //重新定位到標準輸入,linux平臺 return 0; }
import sys
temp = sys.stdout
file = open('f.txt','w')
sys.stdout = file
print (1,2,3)
sys.stdout.close()
sys.stdout = temp
print (1,2,3)
相關推薦
Windows下cmd標準輸入輸出重定向
Command Function command > filename 把標準輸出重定向到一個檔案中 command >> filename
C語言標準輸入輸出重定向
函式:freopen 標頭檔案: stdio.h/cstdio標準輸入重定向:freopen("a.txt","r",stdin);有了這句以後cin, scanf, getc, gets都從檔案”a.txt”裡來啦這個在OJ裡特別有用#ifndef O
標準輸入輸出重定向
函式名:freopen 宣告:FILE *freopen( const char *path, const char *mode, FILE *stream ); 所在檔案: stdio.h 引數說明: path: 檔名,用於儲存輸入輸出的自定義檔名。 mode:
Linux 標準 輸入 輸出 重定向. printf 不輸出到螢幕的解決辦法
方法1: #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <sys/stat.h> #include <fcntl.h&g
shell基礎02 標準文件描述符STDIN,STDOUT,STDERR和輸入輸出重定向
stdin isp pen blank input open 日誌文件 重定向 分開 文件描述符 縮寫 描述
Java 輸入/輸出——重定向標準輸入/輸出
ole catch som align oid int limit 文件的 pan 在System類中提供了如下三個重定向標準輸入/輸出方法。 static void setErr?(PrintStream err) Reassigns the "standar
Shell 腳本學習筆記十:Shell輸入輸出重定向
描述符 獨立 文件重定向 eof 輸出 合並 包含 span 輸出重定向 command > file 將輸出重定向到 file。 command < file 將輸入重定向到 file。 command >> file
8.1 shell介紹 8.2 命令歷史 8.3 命令補全和別名 8.4 通配符 8.5 輸入輸出重定向
8.1 shell介紹 8.2 命令歷史 8.3 命令補全和別名 8.4 通配符 8.5 輸入輸出重定向8.1 shell介紹 8.2 命令歷史 8.3 命令補全和別名 8.4 通配符 8.5 輸入輸出重定向 # Linux shell 基礎 # 8.1 shell 介紹 - 什麽是shell 1
shell介紹,命令歷史,命令補全和別名,通配符,輸入輸出重定向
重定向 輸入輸出 history 筆記內容:l 8.1 shell介紹l 8.2 命令歷史l 8.3 命令補全和別名l 8.4 通配符l 8.5 輸入輸出重定向筆記日期:2017.8.11 8.1 shell介紹Shell俗稱殼(用來區別於核),是指“提供使用者使用界面”的軟件(命令解析器)。sh
shell介紹、命令歷史、命令補全和別名、通配符、輸入輸出重定向
linux基礎shell介紹shell是一個命令解釋器,提供用戶和機器之間的交互,支持特定語法,比如邏輯判斷、循環,每個用戶都可以有自己特定的shellCentOS7默認shell為bash(Bourne Agin Shell)還有zsh、ksh等命令歷史查看歷史命令[root@test76 ~]# cat
輸入輸出重定向
追加 錯誤信息 標準 方式 錯誤輸出 font mil 在屏幕上 有意義 在linux中輸入輸出的定義? 0 標準輸入 1 標準輸出 2 標準錯誤輸出 什麽是輸出重定向? 把原來輸出在屏幕上的結果寫入文件,而不是顯示在
shell介紹、歷史命令、命令補全和別名、通配符、輸入輸出重定向
linuxshell介紹shell是系統跟計算機硬件交互時使用的中間介質,它只是系統的一個工具。在計算機硬件之間還有一層東西——系統內核。如果把計算機硬件比作一個人的軀體,那系統內核就是人的大腦。至於shell,把它比作人的五官似乎更貼切些。言歸正傳,用戶直接面對的不是計算機硬件而是shell,用戶把指令告訴
5周第3次課 shell介紹 命令歷史 命令補全和別名 通配符 輸入輸出重定向
linux中shell介紹 命令歷史 命令補全和別名 通配符 輸入輸出重定向1.shell介紹shell 是一個命令解釋器,提供用戶和機器之間的交互。它支持特定語法,邏輯判斷、循環。比如,我們登陸的終端,它其實就是一個 shell,供我們和機器交互。Linux 下面有很多 shell,每個用戶都可以有自
Linux輸入輸出重定向和文件查找值grep命令
顯示 標準輸入 顏色 localhost 搜索 use mit 其他 host Linux輸入輸出重定向和文件查找值grep命令 一、文件描述符Linux 的shell命令,可以通過文件描述符來引用一些文件,通常使用到的文件描述符為0,1,2。Linux系統實際上
shell介紹,命令歷史記錄,命令和文件名自動補齊;通配符和輸入輸出重定向
數字 51cto ksh 開頭 chat inux shell images 重定向 shell介紹 Shell是系統的用戶界面,提供了用戶與內核進行交互操作的一種接口。它接收用戶輸入的命令並把它送入內核去執行。在計算機硬件之間還有一層東西——系統內核。如果把計算機硬件比作
shell介紹 命令歷史 命令補全和別名 通配符 輸入輸出重定向
oot 歷史 tab鍵 運行 命令補全 cat man base 是什麽 8.1 shell介紹 shell 是一個命令解釋器,提供用戶和機器之間的交互 支持特定語法,比如邏輯判斷,循環 每個用戶都可以有自己特定的shell CentOS7默認shell 為bash(Bou
shell介紹、命令歷史、通配符、輸入輸出重定向
adf size pro 輸入輸出重定向 .com alt adc bbf -o shell介紹 命令歷史 命令補全及別名 通配符、輸入輸出重定向 shell介紹、命令歷史、通配符、輸入輸出重定向
記錄歷史命令,history,命令補全和別名、通配符、輸入輸出重定向
無法訪問 兩個 時間 %d mat roo sts 更改 dir shell shell是一個命令解釋器,提供用戶與機器之間的交互,支持特定的語法(邏輯判斷、循環等);每個用戶都可以有自己特定的shell;centos7默認shell為bash,其他shell還有zsh、k
8.1shell介紹 8.2命令歷史 8.3命令補全和別名 8.4通配符 8.5輸入輸出重定向
bdb ffffff sts text 終端 shel proc http watermark 8.1 shell介紹.查找一下有沒有這2個安裝文件8.2 命令歷史環璄1000,所以只能存1000條記錄‘有時候查到比1000多了,那是因為輸入的命令還沒有寫進這個文件,只存在
二十三、shell介紹、命令歷史、命令補全和別名、通配符、輸入輸出重定向
shell簡介 命令歷史介紹 通配符 輸入輸出重定向 二十三、shell介紹、命令歷史、命令補全和別名、通配符、輸入輸出重定向一、shell介紹shell是系統跟計算機硬件交互使用的中間介質,它只是系統的一個工具。shell和計算機硬件之間還有一層東西——系統內核。若把計算機硬件比作人的軀體,