c - 在 Unix 中更改密码的 perl(或 C)程序?

标签 c perl

嗨,我正在尝试做 this正如答案中提到的使用 perl 但它不起作用。

#!/usr/bin/perl -w
$pipe="data";
$username="mukesh";
$password="mukesh";
open my $pipe, '|chpasswd' or die "can't open pipe: $!";
print {$pipe} "$username:$password";
close $pipe

[root@testgfs2 user_mgmt]# ./tess3.sh
Name "main::pipe" used only once: possible typo at ./tess3.sh line 2.
chpasswd: line 1: line too long
chpasswd: error detected, changes ignored

任何人都可以提出建议吗?出了什么问题。

因为 --stdin 不适用于所有 *nix,我正在尝试使用它

编辑:C 中是否有任何程序可以执行此操作。因为如果 *nixes,这可能对所有版本都有用

最佳答案

你可以试试这个

system("$USERNAME:$PASSWORD | chpasswd");

Based off this answer

关于c - 在 Unix 中更改密码的 perl(或 C)程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14399048/

相关文章:

Perl soap::lite 和复杂数据

c - 如何在c中正确调用另一个函数内的函数?

c - 这个虚拟机如何将指令转换为十六进制值?

c - 在 C 中测量处理器滴答声

perl - Perl 中的 Fork 无法在从文件读取的 while 循环内工作

perl 调用 shell-- interrupt ^C 停止 shell,而不是 perl

c - c中链表中的头节点

arrays - C程序求最大数

linux - 在 Linux/Perl 上获取权限位字符串?

perl - 如何在Perl 5中定义解析语法?