我设法让Ubuntu在移动设备上运行。我需要在它上自动化一些过程,因为没有复杂的设置和焊接线,用户输入是完全不可能的。
我需要运行"parted print“,然后在stdin中输入"yes,fix,fix”,下面是所需的输出:
~ # parted /dev/block/mmcblk0 print
parted /dev/block/mmcblk0 print
Warning: /dev/block/mmcblk0 contains GPT signatures, indicating that it has a
GPT table. However, it does not have a valid fake msdos partition table, as it
should. Perhaps it was corrupted -- possibly by a program that doesn't
understand GPT partition tables. Or perhaps you deleted the GPT table, and are
now using an msdos partition table. Is this a GPT partition table?
Yes/No? yes
yes
yes
Error: The backup GPT table is not at the end of the disk, as it should be.
This might mean that another operating system believes the disk is smaller.
Fix, by moving the backup to the end (and removing the old backup)?
Fix/Ignore/Cancel? fix
fix
fix
Warning: Not all of the space available to /dev/block/mmcblk0 appears to be
used, you can fix the GPT to use all of the space (an extra 569312 blocks) or
continue with the current setting?
Fix/Ignore? fix
fix
fix
Model: MMC SEM16G (sd/mmc)
Disk /dev/block/mmcblk0: 15.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 131kB 262kB 131kB xloader
2 262kB 524kB 262kB bootloader
3 524kB 16.3MB 15.7MB recovery
4 16.8MB 33.6MB 16.8MB boot
5 33.6MB 83.9MB 50.3MB rom
6 83.9MB 134MB 50.3MB bootdata
7 134MB 522MB 388MB factory
8 522MB 1164MB 642MB system
9 1164MB 1611MB 447MB cache
10 1611MB 2684MB 1074MB media
11 2684MB 15.6GB 12.9GB userdata
这是我起草的..。
#! /bin/bash
mkfifo Input
mkfifo Output
#Redirect commandline input from fifo to parted, Redirect output to fifo, background
cat Input &| - parted print >Output &
Line=""
while [ 1 ]
do
while read Line
do
if [ $Line == *Yes\/No\?* ]; then
echo "yes">Input
fi
if [ $Line == *Fix\/Ignore/\Cancel\?* ]; then
echo "fix">Input
fi
if [ $Line == *Fix\/Ignore\?* ]; then
echo "fix">Input
fi
test $Line == *userdata* && break
done<Output
test $Line == *userdata* && break
done
但这是行不通的。如果有人可以帮助我将程序的输出重定向到fifo中,然后分析该数据并将输出定向到另一个fifo中,以便放回原始程序中?所需的结果在第一个代码块中。
发布于 2012-03-02 05:09:30
如果您总是知道所需的输入是什么--如果它们从不随运行而改变--那么您只需重定向来自文件或HERE文档的输入,而不需要做任何复杂的事情。
如果每次运行所需的输入都会发生变化,那么您需要使用shell之外的其他东西,因为它不会使您尝试做的事情成为可能。perl可能是个不错的选择。(这里不需要使用expect,因为您不是在尝试模拟tty。)
https://stackoverflow.com/questions/9523306
复制相似问题