[Php 4, Php 5, Php 7, Php 8]
shell_exec - lệnh thực thi qua shell và trả về đầu ra hoàn chỉnh dưới dạng chuỗi — Execute command via shell and return the complete output as a string
Sự mô tả
shell_exec [Chuỗi $command
]: Chuỗi | Sai | NULL[string $command
]: string|false|null
Ghi chú::
Trên Windows, đường ống bên dưới được mở ở chế độ văn bản có thể khiến hàm bị hỏng đối với đầu ra nhị phân. Xem xét sử dụng popen [] thay vì cho những trường hợp như vậy.popen[] instead for such cases.
Thông số
command
Lệnh sẽ được thực thi.
Trả về giá trị
Một chuỗi chứa đầu ra từ lệnh thực thi, false
nếu đường ống không thể được thiết lập hoặc null
nếu xảy ra lỗi hoặc lệnh không tạo ra đầu ra.string containing the output from the executed command, false
if the pipe cannot be established or null
if an error occurs or the command produces no output.
Ghi chú::
Trên Windows, đường ống bên dưới được mở ở chế độ văn bản có thể khiến hàm bị hỏng đối với đầu ra nhị phân. Xem xét sử dụng popen [] thay vì cho những trường hợp như vậy.
null
both when an error occurs or the program produces no output. It is not possible to detect execution failures using this function. exec[] should be used when access to the program exit code is required.
Errors/Exceptions
Thông sốE_WARNING
level error is generated when the pipe cannot be established.
command
Lệnh sẽ được thực thi.shell_exec[] example
Trả về giá trị
- Một chuỗi chứa đầu ra từ lệnh thực thi,
false
nếu đường ống không thể được thiết lập hoặcnull
nếu xảy ra lỗi hoặc lệnh không tạo ra đầu ra. - Hàm này có thể trả về
null
cả khi xảy ra lỗi hoặc chương trình không tạo ra đầu ra. Không thể phát hiện các lỗi thực thi bằng cách sử dụng chức năng này. EXEC [] nên được sử dụng khi truy cập vào mã thoát chương trình là bắt buộc.
Một lỗi cấp độ E_WARNING
được tạo ra khi đường ống không thể được thiết lập. ¶
Ví dụ
If you're trying to run a command such as "gunzip -t" in shell_exec and getting an empty result, you might need to add 2>&1 to the end of the command, eg:
Won't always work:
echo shell_exec["gunzip -c -t $path_to_backup_file"];
Should work:
echo shell_exec["gunzip -c -t $path_to_backup_file 2>&1"];
command
0
command
1Ví dụ #1 một ví dụ shell_exec [] ¶
Xem thêm
command
2
command
3
command
4
command
1EXEC [] - Thực hiện một chương trình bên ngoài ¶
Escapeshellcmd [] - Escape Shell Metacharacters
command
6
command
7
command
8
command
9
false
0
command
1Trev tại DEVATIATE.CO.uk ¶ ¶
11 năm trước
false
2
false
3
false
4
false
5
command
1smcbride tại msn dot com ¶ ¶
1 năm trước
false
7
false
8
false
9
null
0
null
1
null
2
null
3
null
4
null
1
null
6
null
7
null
8
null
9
null
0
null
1
command
1Alexandre Dot Schmidt tại Gmail Dot Com ¶ ¶
6 năm trước
null
3
null
4
null
5
null
6
command
1Rgemini ¶ ¶
1 năm trước
null
8
null
9
E_WARNING
0
E_WARNING
1
E_WARNING
2
command
1Alexandre Dot Schmidt tại Gmail Dot Com ¶ ¶
6 năm trước
E_WARNING
4
E_WARNING
5
E_WARNING
6
E_WARNING
7
command
1Rgemini ¶ ¶
11 năm trước
E_WARNING
9
0
command
1smcbride tại msn dot com ¶ ¶
1 năm trước
2
3
command
1Alexandre Dot Schmidt tại Gmail Dot Com ¶ ¶
Xem thêm
5
6
7
8
9
If you're trying to run a command such as "gunzip -t" in shell_exec and getting an empty result, you might need to add 2>&1 to the end of the command, eg:
0
command
1EXEC [] - Thực hiện một chương trình bên ngoài ¶
Escapeshellcmd [] - Escape Shell Metacharacters
If you're trying to run a command such as "gunzip -t" in shell_exec and getting an empty result, you might need to add 2>&1 to the end of the command, eg:
2
If you're trying to run a command such as "gunzip -t" in shell_exec and getting an empty result, you might need to add 2>&1 to the end of the command, eg:
3
If you're trying to run a command such as "gunzip -t" in shell_exec and getting an empty result, you might need to add 2>&1 to the end of the command, eg:
4
If you're trying to run a command such as "gunzip -t" in shell_exec and getting an empty result, you might need to add 2>&1 to the end of the command, eg:
5Trev tại DEVATIATE.CO.uk ¶ ¶
11 năm trước
If you're trying to run a command such as "gunzip -t" in shell_exec and getting an empty result, you might need to add 2>&1 to the end of the command, eg:
6
If you're trying to run a command such as "gunzip -t" in shell_exec and getting an empty result, you might need to add 2>&1 to the end of the command, eg:
7
If you're trying to run a command such as "gunzip -t" in shell_exec and getting an empty result, you might need to add 2>&1 to the end of the command, eg:
8
If you're trying to run a command such as "gunzip -t" in shell_exec and getting an empty result, you might need to add 2>&1 to the end of the command, eg:
9
Won't always work:
0
echo shell_exec["gunzip -c -t $path_to_backup_file"];
command
1smcbride tại msn dot com ¶ ¶
1 năm trước
Won't always work:
2
echo shell_exec["gunzip -c -t $path_to_backup_file"];
Won't always work:
3
echo shell_exec["gunzip -c -t $path_to_backup_file"];
Won't always work:
4
echo shell_exec["gunzip -c -t $path_to_backup_file"];
Won't always work:
5
echo shell_exec["gunzip -c -t $path_to_backup_file"];
Won't always work:
echo shell_exec["gunzip -c -t $path_to_backup_file"];
6
Alexandre Dot Schmidt tại Gmail Dot Com ¶ ¶
Escapeshellcmd [] - Escape Shell Metacharacters
Won't always work:
7
echo shell_exec["gunzip -c -t $path_to_backup_file"];
Trev tại DEVATIATE.CO.uk ¶ ¶
11 năm trước
Won't always work:
8
echo shell_exec["gunzip -c -t $path_to_backup_file"];
smcbride tại msn dot com ¶ ¶
1 năm trước
Won't always work:
9
echo shell_exec["gunzip -c -t $path_to_backup_file"];
Should work:
0
echo shell_exec["gunzip -c -t $path_to_backup_file 2>&1"];
Should work:
1
echo shell_exec["gunzip -c -t $path_to_backup_file 2>&1"];
Should work:
2
echo shell_exec["gunzip -c -t $path_to_backup_file 2>&1"];
command
1Alexandre Dot Schmidt tại Gmail Dot Com ¶ ¶
6 năm trước
Should work:
4
echo shell_exec["gunzip -c -t $path_to_backup_file 2>&1"];
Should work:
5
echo shell_exec["gunzip -c -t $path_to_backup_file 2>&1"];
Should work:
echo shell_exec["gunzip -c -t $path_to_backup_file 2>&1"];
6Rgemini ¶ ¶
13 năm trước
Should work:
7
echo shell_exec["gunzip -c -t $path_to_backup_file 2>&1"];
Should work:
8
echo shell_exec["gunzip -c -t $path_to_backup_file 2>&1"];
command
1Eric Dot Peyremorte tại IUT-Valence Dot Fr ¶ ¶
1 năm trước
command
00
command
01
command
02
command
03
command
04
command
05
command
06
command
07
command
1Alexandre Dot Schmidt tại Gmail Dot Com ¶ ¶
11 năm trước
command
09
command
10
command
11
command
12
command
1smcbride tại msn dot com ¶ ¶
Escapeshellcmd [] - Escape Shell Metacharacters
command
14
command
15
Won't always work:
4
echo shell_exec["gunzip -c -t $path_to_backup_file"];
command
17
command
18Trev tại DEVATIATE.CO.uk ¶ ¶
11 năm trước
command
19
smcbride tại msn dot com ¶ ¶
6 năm trước
command
20
command
21
command
1Rgemini ¶ ¶
11 năm trước
command
23
command
24
command
25
command
1smcbride tại msn dot com ¶ ¶
11 năm trước
command
27
command
28
command
1smcbride tại msn dot com ¶ ¶
6 năm trước
command
30
command
31
command
1Rgemini ¶ ¶
11 năm trước
command
33
command
34
command
35
command
1smcbride tại msn dot com ¶ ¶
11 năm trước
command
37
command
38
command
39smcbride tại msn dot com ¶ ¶
1 năm trước
command
40
Alexandre Dot Schmidt tại Gmail Dot Com ¶ ¶
6 năm trước
command
41
command
42
command
43
command
44
command
45
command
46
command
47
command
1Rgemini ¶ ¶
6 năm trước
command
49
command
50
command
51
command
1Rgemini ¶ ¶
11 năm trước
command
53
command
54
command
1smcbride tại msn dot com ¶ ¶
1 năm trước
command
56
command
57
command
58
command
59
command
60
command
61
command
62
command
63
command
1