2011-07-29 65 views
1

是否可以在一個exec命令中運行多個命令?我需要抓住從SVG文件的一些圖片,這變種速度太慢:在一行中運行多個inkscape命令

exec('inkscape file.svg --export-id=g123 --export-png=img1.png'); 
exec('inkscape file.svg --export-id=g124 --export-png=img2.png'); 
exec('inkscape file.svg --export-id=g125 --export-png=img3.png'); 

所以我需要在同一行做的一切。我已經試過了:

exec('inkscape file.svg --export-id=g125 --export-png=img3.png inkscape file.svg --export-id=g123 --export-png=img1.png'); 

但是這隻提取最後一張圖片。

回答

1

exec()可能不慢。 Server/inkscape速度很慢。

+0

即使你把它到一行(使用';'),它不會更快。 Inkscape是瓶頸(正如@Genesis已經說過的)。 @Genesis他爲什麼要換殼? Inkscape是瓶頸,因此將PHP更改爲shell並不重要,是嗎? – elslooo

+0

@TimvanElsloo:刪除最後一句話:) – genesis

2

exec()本身並不慢。但每次打電話時,首先啓動Inkscape,執行操作並再次關閉。也就是說,需要這麼長時間。

不幸的是,Inkscape沒有批處理模式。你可以使用Gimp,它可以批量執行相同的操作。

1

您可以在shell模式下運行Inkscape,並通過向其標準輸入寫入命令與它通信。如果你不想實現它在PHP中你可以寫一個簡單的外殼包裝,做它 你,例如:

#!/bin/bash 
SVG="$1" 
shift 
(
while [ "$1" != "" ] ; do 
    echo "\"--file=$SVG\" \"--export-id=$1\" \"--export-png=$2\"" 
    shift 2 
done 
echo "quit" 
) | \ 
    /path/to/inkscape --shell 2>/dev/null 

,然後用它像這樣

exec("/path/to/wrapper file.svg g123 img1.png g124 img2.png g125 img3.png"); 
相關問題